I updated the packages with conda update --all and was using jupyter to work. Before the update, everything was working, but now jupyter doesn't import any module beside the sys, os, copy and time. Numpy, matplotlib and theano are not being imported. But they are definitely in the conda list... the python version is 2.7.12
When I updated with conda, I remember that there was a message that numpy was being deprecieted due to conflicts. Now in the conda list I have numpy 1.11.1.
I'm new in python, so I don't understand the import error. Before uninstalling everything again, I would like to understand what the problem is to learn and of course to continue using jupyter ;)
I found this post https:// github.com/jupyter/notebook/issues/397 (sorry I can't link it, I'm new here) which seems to be a problem related to mine or similar, but I don't think I understand it so well... so before I break more I wanted to ask here!
Is jupyter badly "connected" to anaconda? How can I check where the packages are being searched? For any comment on this I would be very grateful!!
Here are the cells of jupyter:
cells of jupyter
and the Error I get:
ImportError
Thanks!
That import error is due to change in environment of the jupyter notebook. You might have installed the packages in one environment and you are running the jupyter notebook in another environment.
I have got two environments (envs) in my Anaconda folder. I have Anaconda3 folder to be specific).
(windows key+cmd) -> open the windows command prompt run as administrator.
Activate (name of the environment) -> eg.: activate tensorflow-gpu
Start installing packages using conda install
Note: For each environment you need to install all the packages you want to use, separately using the same process. This solution is for windows users, might work for linux users not sure though.
Additionally to make sure your conda environment is up to date run:
conda update conda
conda update anaconda
For more information: https://pradyumnamajumder.wordpress.com/2017/09/30/solution-to-the-python-packages-import-error-in-jupyter/
I followed the idea as in here and changed the file that launches the root jupyter command (cf. cat /dir_where_installed/anaconda2/bin/jupyter and the jupyter-notebook ( cf. cat /dir_where_installed/anaconda2/bin/jupyter-notebook).
It was set as in the anaconda environment conda info --envs as expected (both files had in the first line something like #! /dir_where_installed/anaconda2/bin/python), but for some reason after the update I did and even after installing again everything(!), jupyter wasn't taking that path, instead it was importing from the 'stock' python (apparently).
Anyway, I changed both lines with #! to take the path as in the output of which python.
Summary:
check path in cat /dir_where_installed/anaconda2/bin/jupyter and cat /dir_where_installed/anaconda2/bin/jupyter-notebook
which python out put should be something like /usr/bin/python
substitute the lines in both files starting with #! with #! /usr/bin/python
I'm not sure if this is a good idea, but it worked for me and now I can import all packages in jupyter. If anyone has any idea if this is a bad idea or a better solution, please let me know!
Related
I am working on a remote machine for my internship and ran into the following problem.
I ran conda install -c huggingface -c conda-forge datasets, which ended up taking ages (and for some reason downloaded a lot of useless packages) and seemingly got stuck, so I ctrl-c'ed the process. From there on, running source ./miniconda3/bin/activate would take upwards of 20 minutes. I tried deleting the entire folder ./miniconda3 and re-installing it from the shell file -- that didn't help.
I interact with conda using VSCode with Python and Jupyter Notebook extensions installed. I re-installed these extensions too out of despair, it also didn't fix the issue. I cannot run any cells in Jupyter, because activating the virtual environement times out. Is there something so that conda activation takes 1-2 seconds like it used to?
I'm not sure if this will fix it for you, but you could try making sure that you full uninstall miniconda before you re-install it. It makes changes to bashrc and has some other hidden folders. The vscode extension isn't going to be able to handle a 20 minute start up wait, so you'll need to resolve that issue first.
https://zditect.com/guide/python/uninstall-miniconda.html
Also I'm not sure that you should be calling source on the activation function of miniconda. At least for me, when using miniconda you should end up with conda on your terminal path. Then you just use conda activate to activate the environment you are working with.
I'm trying to import tensorflow as ts in my script. While everything is fine in a Notebook, when I try to recreate the same script in a .py file the import returns the following, popular message:
ModuleNotFoundError: No module named 'tensorflow'
Note that both Jupyter and terminal are using the same virtual environment. In Notebook it's picked as a Kernel and in terminal it's activated with conda.
I was convinced the whole Kernel/env idea was about preventing exactly that kind of situations. Although I'm new to python so maybe I'm missing something basic.
Also, this might have something to do with that I'm using an M1 and macos, so I have the tensorflow-macos installed. But please consider there might be other reasons.
Make sure your pyenv installation doesn't interfere with the conda environments. Pyenv can overrule which python installation is used even if the conda environment has picked another. In my case it was the reason. Jupyter Notebook wasn't affected by pyenv. There are two solutions:
Remove pyenv
Make sure it is clear to you how both pyenv and conda are affecting your setup and correct it. Some considerations and suggestions are mentioned in this question: Installing anaconda with pyenv, unable to configure virtual environment
I apologize in advance for my poor vocabulary - I do not know much about environments, paths, and things of the sort. I am on macOS Catalina.
I created a program using Spyder from Anaconda. My program uses packages like pandas and numpy which are built into Anaconda. I used to be able to run the program in Terminal with the command: $ python3 app.py.
However, I recently downloaded Python 3.9.1 from https://www.python.org/downloads/mac-osx/. Ever since then, I have been unable to run the program in Terminal because of missing package errors like
import numpy as np
ModuleNotFoundError: No module named 'numpy'
I went to my applications folder, right clicked on Python 3.9.1, and clicked Move To Trash. This did not solve my problem. I reinstalled Anaconda (I did not uninstall it - just simply installed again), but that also did not solve my problem. I am able to run the program in Spyder (from Anaconda), but I wish to run it in Terminal again.
I believe the solution is simple, but I am not sure what to do. I have tried searching and reading but I am not familiar with the terminology. I think I just need to reset the environment, but I am not sure.
Anaconda is used for creating closed enviorments, so you don't need to thrash your computer with global packages.
Imagine you have 2 different projects. Project A works only on python 3.2 and Project B works on 3.8.
That's where anaconda comes in.Managing enviorments with conda
conda create -n PROJECTA python=3.2
conda create -n PROJECTB python=3.8
Now activate env you wish to work with. For macOS
source activate PROJECTA
Now you should see (PROJECTA) instead of (base)
Now inside this PROJECTA you can install modules you require like
pip install numpy
and when executing .py file
move to dir with your app.py file and
python3 app.py
this will be opened in conda enviorment you created and activated, using modules you installed in this env.
You can still edit py file and execute it through shell, but it will throw errors if you try to run it from IDE without linking project to respected conda enviorment.
If you are using PyCharm Configure a Conda vir env in PyCharm
You must create separate environments for every projects or it will get messed up.
conda create -n name_of_environment python=3.6
You must not delete the python folder into trash rather uninstall it Python 3.9.1 and remove its path from the directory.
In short if you run python from terminal and it is not supporting your Installed anaconda packages . You should use anaconda prompt instead of CMD.
Because your anaconda is not added to path rather then it picks up the python 3.9 you have installed from Python 3.9.1 from https://www.python.org/downloads/mac-osx/. ( This is the python with separate environment then anaconda so it wont detect anaconda packages ).
When you run the cmd and enter python it runs the python that you downloaded and installed rather then Anaconda
At the time of installing anaconda it gives option to add conda variables to path you can select those at installing stage / or add manually
I want to follow along a course about deeplearning. This course has a github repo, where all of the codes are available. We need to use anaconda, create an environment based on the yaml file, and run a jupyter notebook within that environment.
There's even a test notebook to check whether the installation and environment creating process was successful. I have created the environment as the description said, the installation of the packages seemed to be good.
For the first few command, I get the required outputs, but the notebook doesn't seem to start from the correct environment, it gives me
C:\Users\user\Anaconda3\Lib\site-packages\jupyter.py
instead of
C:\Users\paperspace\Anaconda3\envs\ztdl\lib\site-packages\jupyter.py
And it can't find the packages that I have just installed before. For example, when it has to include sklearn it gives me:
No module named 'sklearn.__check_build._check_build'
Installing them from command line with pip/conda solves this.
I have tried to install manually ipykernel, nb_conda, jupyter as other posts say. I ran jupyter notebook after I activated the conda environment from the anaconda prompt. But none of these helped me. As I open the kernel menu, I can see that the proper ztdl anaconda environment is the active one.
I also removed anaconda from the %PATH%, and added it again afterwards with c:\Users\user\Anaconda3\ .
I have no idea what should I do to run the notebook within this given anaconda environment, so I can access the installed packages. Thanks in advance, any help is appreciated.
I have Anaconda 2 with Python 2.7 running on Windows 8. I have installed GraphLab and GraphLab has created a separate environment in Anaconda -- the gl-env environment.
I am facing problems in importing libraries that I have installed successfully via conda through the Windows Commander from the Scripts subdirectory.
For example, I installed wget successfully but when I try to import it from my Jupyter Notebook from the gl-env environment I get an error message that the module does not exist.
I suspect that this error has something to do with the two environments and the PATH content but I do not know enough to figure that out. I made a research in Stackoverflow and it seems that other people have had importing problems relating to different environments but as far as I understand there is not specific advice I can implement.
Your advice will be appreciated.
Try adding a cell in Jupyter directly identifying/appending the path...
import graphlab
graphlab.path.append(path)
...whatever the path may be.
Dunno if you still need it, but for future users, once a new environment is created, once must install the specific libraries and modules one wants accessible in that environment.
In this case, once the gl-env is activated, do a conda install wget again.