I am taking two courses at uni each requirering you to use two different versions of python, and I am new to both. One requires you to use python 3 with jupyter notebook and the other to use python 2 with Spyder. I have installed both through anaconda, and python3 is set as my default.
I am trying to import packages from SciKit Learn to use in Spyder with Python 2.7. When i try pip install -U scikit-learn in the command prompt, it says it is allready up to date but refers to the default folder of Anaconda3\\lib\\sitepackages, which obviously does not help me install it in python 2. How do I change this to update the package in Python2 instead?
Thank you!
Double check which version of python that the pip you're using refers to:
$ pip -V
# pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
$ pip2 -V
# pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
$ pip3 -V
# pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
I'm not sure exactly what your setup looks like, but if it's defaulting to python 3.5 like mine does, then doing a pip install
will install the package for python3 instead of python2
Hopefully that helps!
It is always better to use virtualenv to manage different python environments.
virtualenv -p /usr/bin/python2.7 yourenvname
For activation use, source ./yourenvname/bin/activate
When you activate the virtual environment and use pip command, it will use the pip from the local bin path. (Use which pip
or pip -V
to check the location)
Now as I understand you are using Anaconda, you can create a new virtual environment using the conda
command.
conda create -n yourenvname python=x.x anaconda
For activation use, source activate yourenvname
If you do not use these solutions, then you want to find the anaconda's python2.7 bin directory and invoke it. (Try with pip2
)
Resources - https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.