I have created a new virtual environment "pytorchplay" within Anaconda Navigator to play around with the Pytorch library using Python 3.8. To this environment I loaded Pytorch and Jupyter (and all dependent sources). If I launch an Anaconda terminal prompt from that newly created environment within Navigator and type "conda list," Pytorch appears in the list. If I launch an iPython terminal prompt FROM THE SAME newly created environment and type "pip list," Pytorch does not appear. If I initiate a jupyter notebook FROM THE SAME environment, and type "pip list," Pytorch also does not appear. In this last case, I do have a local kernel instantiated with the correct virtual environment. So, three versions of ostensibly the same instance, but with differing libraries/packages. How is this possible? (Apologies if some of the language is imprecise, I'm learning...)
I have checked any number of similar posts and questions, but cannot seem to locate the correct fix. Should it be helpful, I have checked the paths. These appear below. I would appreciate any assistance that can be provided. Thanks!
From the Anaconda shell:
(pytorchplay) C:\Users\rk264116>echo %PATH%
C:\Users\rk264116\Miniconda3\envs\pytorchplay;
C:\Users\rk264116\Miniconda3\envs\pytorchplay\Library\mingw-w64\bin;
C:\Users\rk264116\Miniconda3\envs\pytorchplay\Library\usr\bin;
C:\Users\rk264116\Miniconda3\envs\pytorchplay\Library\bin;
C:\Users\rk264116\Miniconda3\envs\pytorchplay\Scripts;
C:\Users\rk264116\Miniconda3\envs\pytorchplay\bin;C:\Users\rk264116\Miniconda3\condabin;
C:\Users\rk264116\Miniconda3;C:\Users\rk264116\Miniconda3\Library\mingw-w64\bin;
C:\Users\rk264116\Miniconda3\Library\usr\bin;
C:\Users\rk264116\Miniconda3\Library\bin;
C:\Users\rk264116\Miniconda3\Scripts;
And from the iPython shell:
In [5]: sys.path
Out[5]:
['C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\Scripts',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\python38.zip',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\DLLs',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\lib',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay',
'',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\lib\\site-packages',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\lib\\site-packages\\win32',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\lib\\site-packages\\win32\\lib',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\lib\\site-packages\\Pythonwin',
'C:\\Users\\rk264116\\Miniconda3\\envs\\pytorchplay\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\rk264116\\.ipython']
The explanation is simply that there is a name discrepancy between the conda package (and the libraries name) PyTorch and the name of the python module that you are importing torch.
The package that conda installs and therefore knows about is called pytorch, hence you see that from anaconda navigator or when running conda list.
pip on the other hand is oblivious of what conda does. Since it is only able to manage python modules, it sees the torch package present in your environment.
Related
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'm new using Jupyter on Miniconda and I was having a problem while importing packages (ImportError: DLL load failed ), looking for answers the solution was to initialize a base environment in my bash.
I used to initialize jupyter typing jupyter notebook in bash, but using the solution given, I have to activate conda activate bash and then type jupyter notebook. What is the difference between starting Jupyter the way I used to and this new way?
conda activate command activates a virtual environment. It is an isolated environment so all packages you installed in the virtual environment cannot be used outside it. When you start bash, you are in the base environment and it seems that you installed your Jupiter in bash environment so you cannot use bash's Jupiter in base environment and vice versa. It may be a little annoying at the beginning, but it can let you use different environments for different purposes. For example, since pip only allows one version of a specific package to be installed, different environments can let you test a new version of a package without breaking the functionality of the original program.
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.
Anaconda3 5.3.0 64bit.
During installation process, I check the option to add Anaconda in my PATH environment variable. Then it does not recommend me to do that. It says:
Instead, open Anaconda with the Windows Start menu and select "Anaconda (64-bit)". This "add to PATH" option makes Anaconda get found before previously installed software, but may cause problems requiring you to install and reinstall Anaconda.
What does it really mean? I would like to add it to PATH because I would like to work also by means of the command line interface, but I would not like to have problems.
If Python is already installed and is being used by other programs, setting the conda path again can lead to unwanted conflicts.
For this reason Anaconda provides a separate cmd line/Powershell interface called Anaconda prompt which sets the PATH as long as the shell is open.
If you're installing Python for the first time using Anaconda, there shouldn't be any problems.
You can create environments using conda if you want to work with different python versions. Anaconda will automatically set the path for both scenarios once the environment is activated.
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.