I'm sure this might be a common problem but I've scoured the StackOverflow and read through all the recommended posts that StackOverflow gave me before posting. However, I've installed tensorflow on conda but not on pip. When I run Python, I can't run import tensorflow since it gives me ModuleNotFoundError: No module named 'tensorflow'. This leads me to believe that conda installs the packages to a different place than pip, but I'm not sure how to make them install to the same place. I recall a long time ago, the problem being related to usr/bin and usr/local/bin or something, but I don't remember how that goes or the solution.
Any links / tips would be appreciated!
Please follow the below steps:
The below command will list all the environments in the system and their path
conda env list
Please activate the corresponding environment using the below command
conda activate <env_name>
You can list the pip/conda packages that you have installed in the activated environment using the below command
pip freeze
conda list
If tensorflow is not listing, please install tensorflow again using the below command
pip install tensorflow
If still you are facing issue check the PATH variable in control panel and set python path.
I just installed PyCharm and Anaconda. I installed PyTorch to Anaconda and i can even use "import torch" in Anaconda. I've created a new Project in PyCharm with the Anaconda Interpreter but i still can't use PyTorch in PyCharm.
I had this problem also. Program that imported torch worked fine at anaconda prompt running in my pytorch env, but when i ran pycharm from the windows shortcut and EVEN set my environment to use pytorch env, it would complain torch could not be imported.
When i ran pycharm from the prompt as shown, it worked.
If you used a bash script and the conda environment to run python codes in your PyCharm IDE.
You also need source activate myenv in your bash script.
Like this:
#!/usr/bin/env bash
source activate myenv
python test.py
source deactivate
I got the same problem and you that how i solved the problem:
1- when you open project choose conda as your project interpreter as shown here
2- in your project go to setting -> project: project name -> Project Interpreter check that you are using Conda Package Manager and your anaconda local settings
I got same problem and solved it:
After you installed anaconda, source activate your own envrionment.
Install pycharm-community and pytorch follow their official instructions.
Start pycharm-community in the same anaconda environment.
Loading your own project, followed instructions as Manuel Lagunas
Finally, you have to install packages of torch in the environment of pycharm: pictures as:
press '+' on the right side to install
you can choose packages of torch by typing 'torch'
Finally solved this in Windows 10 after sinking an entire morning into it.
Create a new Conda environment (via PyCharm or however you fancy)
Navigate to C:\Your\Environment\Path\Scripts in a command terminal
Mine looks like this: C:\ProgramData\Anaconda3\envs\Snek_V2\Scripts
Find what commands you would need for a pip install from the PyTorch website
They'll look something like this:
pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl
pip3 install torchvision
In the command terminal, you want to enter those commands with one difference; you'll need to replace pip3 with pip.exe. As you've navigated to the exact environment you plan to work in, this will be the pip relevant to you.
e.g. pip.exe install torchvision
Open PyCharm and open the project that's working in the Conda environment we just set up.
If you open up a Python Console, you should now be able to enter import torch and not have any errors pop up in response.
I want to import sklearn but there is no module apparently:
ModuleNotFoundError: No module named 'sklearn'
I am using Anaconda and Python 3.6.1; I have checked everywhere but still can't find answers.
When I use the command:
conda install scikit-learn should this not just work?
Where does anaconda install the package?
I was checking the frameworks in my python library and there was nothing about sklearn only numpy and scipy.
Please help, I am new to using python packages especially via anaconda.
You can just use pip for installing packages, even when you are using anaconda:
pip install -U scikit-learn scipy matplotlib
This should work for installing the package.
And for Python 3.x just use pip3:
pip3 install -U scikit-learn scipy matplotlib
Will leave below two options that may help one solve the problem:
Using conda
Using pip
One might want to consider the notes at the end, specially before resorting to the 2nd option.
Option 1
If one wants to install it in the root and one follows the requirements - (Python (>= 2.7 or >= 3.4), NumPy (>= 1.8.2), SciPy (>= 0.13.3).) - the following should solve the problem
conda install scikit-learn
Alternatively, as mentioned here, one can specify the channel as follows
conda install -c anaconda scikit-learn
Let's say that one is working in the environment with the name ML.
Then the following should solve one's problem:
conda install -n ML scikit-learn
# or
conda install -n ML -c anaconda scikit-learn
Option 2
If the above doesn't work, on Anaconda Prompt one can also use pip (here's how to pip install scikit-learn), so the following may help
pip install scikit-learn
However, consider the last note below before proceeding.
Notes:
When using Anaconda, one needs to be aware of the environment that one is working.
Then, in Anaconda Prompt, one needs to run the following
conda $command -n $ENVIRONMENT_NAME $IDE/package/module
$command - Command that one intends to use (consult documentation for general commands)
$ENVIRONMENT NAME - The name of one's environment (if one is working in the root,
conda $command $IDE/package/module is enough)
$IDE/package/module - The name of the IDE or package or module
If one needs to install/update packages, the logic is the same as mentioned in the introduction. If you need more information on Anaconda Packages, check the documentation.
What is the flag -c.
pip doesn't manage dependencies the same way conda does and can, potentially, damage one's installation.
If you are using Ubuntu 18.04 or higher with python3.xxx then try this command
$ sudo apt install python3-sklearn
then try your command. hope it will work
I did the following:
import sys
!{sys.executable} -m pip install sklearn
I've tried a lot of things but finally, including uninstall with the automated tools. So, I've uninstalled manually scikit-learn.
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/sklearn
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/scikit_learn-0.20.0-py3.6.egg-info
And re-install using pip
sudo pip3.6 install -U scikit-learn
Hope that can help someone else!
This happened to me, I tried all the possible solutions with no luck!
Finaly I realized that the problem was with Jupyter notebook environment, not with sklearn!
I solved the problem by re-installing Jupyter at the same environment as sklearn
the command is: conda install -c anaconda ipython. Done...
The other name of sklearn in anaconda is scikit-learn. simply open your anaconda navigator, go to the environments, select your environment, for example tensorflow or whatever you want to work with, search for scikit_learn in the list of uninstalled packages, apply it and then you can import sklearn in your jupyter.
SOLVED:
The above did not help. Then I simply installed sklearn from within Jypyter-lab, even though sklearn 0.0 shows in 'pip list':
!pip install sklearn
import sklearn
What I learned later is that pip installs, in my case, packages in a different folder than Jupyter. This can be seen by executing:
import sys
print(sys.path)
Once from within Jupyter_lab notebook, and once from the command line using 'py notebook.py'.
In my case Jupyter list of paths where subfolders of 'anaconda' whereas Python list where subfolders of c:\users[username]...
On Windows, I had python 3+ version. pip version - 22.3.1
I had installed:
pip install sklearn
But, it seems it is deprecated with scikit-learn.
So, I did:
pip install scikit-learn
And, it worked!!!
Cause
Conda and pip install scikit-learn under ~/anaconda3/envs/$ENV/lib/python3.7/site-packages, however Jupyter notebook looks for the package under ~/anaconda3/lib/python3.7/site-packages.
Therefore, even when the environment is specified to conda, it does not work.
conda install -n $ENV scikit-learn # Does not work
Solution
pip 3 install the package under ~/anaconda3/lib/python3.7/site-packages.
Verify
After pip3, in a Jupyter notebook.
import sklearn
sklearn.__file__
~/anaconda3/lib/python3.7/site-packages/sklearn/init.py'
I had the same problem.
The issue is when we work on multiple anaconda environments, not all packages are installed in all environments.
you can check your conda environment by writing the following code in anaconda prompt:
conda env list
then you can check the packages installed in each environment :
conda list -n NAME_OF_THE_ENVIRONMENT
for me, the environment that I was working with , was missing sklearn, although the package was installed in the other environments.
therefore, I just simply installed sklearn package in that particular environment
conda install -n NAME_OF_THE_ENVIRONMENT scikit-learn
and the issue was resolved
install these ==>> pip install -U scikit-learn scipy matplotlib
if still getting the same error then ,
make sure that your imoprted statment should be correct. i made the mistike while writing ensemble so ,(check spelling)
its
should be >>> from sklearn.ensemble import RandomForestClassifier
I had the same issue as the author, and ran into the issue with and without Anaconda and regardless of Python version. Everyone's environment is different, but after resolving it for myself I think that in some cases it may be due to having multiple version of Python installed. Each installed Python version has its own \Lib\site-packages\ folder which can contain a unique set of modules for that Python version, and where the IDE looks into folder path that doesn't have scikit-learn in it.
One way to try solve the issue: you might clear your system of all other Python versions and their cached/temp files/system variables, and then only have one version of Python installed anywhere. Then install the dependencies Numpy and Scipy, and finally Scikit-learn.
More detailed steps:
Uninstall all Python versions and their launchers (e.g. from Control Panel in Windows) except the one version you want to keep. Delete any old Python version folders in the Python directory --uninstalling doesn't remove all files.
Remove other Python versions from your OS' Environment Variables (both under the system and user variables sections)
Clear temporary files. For example, for Windows, delete all AppData Temp cache files (in C:\Users\YourUserName\AppData\Local\Temp). In addition, you could also do a Windows disk cleanup for other temporary files, and then reboot.
If your IDE supports it, create a new virtual environment in Settings, then set your only installed Python version as the interpreter.
In your IDE, install the dependencies Scipy and Numpy from the module list first, then install Scikit-Learn.
As some others have suggested, the key is making sure your environment is set up correctly where everything points to the correct library folder on your computer where the Sklearn package is located. There are a few ways this can be resolved. My approach was more drastic, but it turns out that I had a very messy Python setup on my system so I had to start fresh.
Using Anaconda-navigator UI environment
When running Anaconda-navigator:
Choose the 'Environments' tab on the left and create a new environment (e.g. ML - see Gonçalo Peres answer above, I made one called 'CourseraML').
Set Python version 3.7 (for Coursera course Applied Machine Learning in Python). Also include R.
Then find modules to install using the 'not installed' drop-down menu item. Search for each module needed in the search bar and select. sklearn is part of scikit-learn. Select it and install (it should find all relevant dependencies). Modules needed for Applied ML course: seaborn, numpy, scikit-learn, pandas, matplotlib
You'll need to restart Jupyter Notebook and reopen your file.
Command line version of above:
conda install -n CourseraML seaborn scikit-learn pandas numpy matplotlib graphviz
Causes
-your jupyter notebook might be importing the sklearn and other libraries from the
another the location(path) than the libraries from conda or pip.
MY Problem
In my case, My jupyter notebook was importing the libraries for snap manager. Since, I install jupyter using the snap instead of other ways.
You can check where other libraries are being imported in jupyter using code:
import cv2 as cv
print(cv.__file__)
Solution
So , I uninstall jupyter notebook and then install notebook using conda.
sudo snap remove jupyter
conda install -c conda-forge notebook
I just started to learn how to use Anaconda to manage packages. I am trying to install tensorflow in conda environment. So first of all, I create an environment by:
conda create -n tensorflow
Then, I source it by:
source activate tensorflow
I can see my prompt changed so I think it is going right.
I notice that it seems that the tensorflow environment is copying from ~/anaconda2/lib/ where I do have my root version python2.7 and tensorflow0.12.0
I installed a new version Python in tensorflow environment by:
conda install python=3.5
Then, I follow the steps to install tensorflow by:
pip install --ignore-installed --upgrade TF_PYTHON_URL
However, when I do conda list, I can only see Python3.5 but not tensorflow1.0. I also failed to import tensorflow when I am in Python.
So I have two questions that really confuse me.
Why does the pip installed tensorflow not show up when I do conda list?
Although I conda install python=3.5 and I can see it from conda list, I am not using python 3.5 when I enter Python directly. It seems still using Python2.7, which comes from my root environment.
I appreciate any tutorial on how anaconda works.
I think your pip install is installing into the global environment instead of
tensorflow. Why don't you try installing by specifying the path? For example pip install --target $HOME/anaconda3/tensorflow tensorflow(Where the first tensorflow is your environment and the second is the actual package).
I just saw the last two questions. So you actually see the tensorflow you installed with pip? I am confused now. Type which pip to see if it is running from the tensorflow environment or the global. You could also try source deactivate before source activate tensorflow just to make sure that you are not using a different environment, then run which python. It should show your new environment.
If you want to create an environment using a specific version of Python (rather than the system default), you can do for example:
conda create --name myCoolEnv python=3.5
and then activate with
source activate myCoolEnv
You can read more about Anaconda environments here.
Pip Installed tensor flow (CPU only... https://www.tensorflow.org/install/install_windows) in an anaconda environment, says it successfully installed but when I go to use tensor flow (with environment activated) it displays an error saying "ImportError: No module named 'tensorflow'".
However, After i installed pandas package, and it successfully runs. i ran an update to python=3.5 for the environment (because my anaconda is 2.7 version), and tried using this link https://github.com/tensorflow/tensorflow/issues/6136 for help also. Weird that other packages run but not tensor flow. Using a PC windows 10 with intel CPU and amd graphics. Any suggestions would be helpful.
First check which environment you are using right now.
If it helps open the anaconda navigator and see whether you have TensorFlow installed in the "installed" tab of that particular environment.
Check the following on jupyter noteook and see what python version you're using in that environment because the environment that you are using might have a different python version after all.
from platform import python_version
print(python_version())
If the versions are different, try removing the TensorFlow installation and reinstalling it according to your python version. environment and recreating the same environment pip install --ignore-installed --upgrade tensorflow=='version_for_your_requirement"
If the situation is still there, https://www.youtube.com/watch?v=tPq6NIboLSc see here the steps followed in the video. Though its a slightly different scenario, you will get the gist of it pretty quickly as to how we can make another environment for our work and about installing TensorFlow properly.
Tensorflow supports 64-bit Python version. Make sure you have installed 64-bit Python 3.5/3.6/3.8 version.
Install Tensorflow using following steps
#check current python version
python --version
#Create the virtual environment
conda create -n tf python=PYTHON_VERSION
#Activate the tf environment
conda activate tf
#Install Tensorflow
pip install tensorflow