How to resolve between two python 3 installations? - python

In my terminal, when I run:
pip -V
It gives:
pip 9.0.1 from /home/abhor/anaconda3/lib/python3.6/site-packages (python 3.6)
And when I run:
pip3 -V
It gives:
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.6)
I want only 1 python3.6 to be there in my system, in case there are problems in the future. How to do this?

I don't see any harm to keep it this way however you can uninstall any one of them.
and its always recommended that you use separate virtual environment for your each of your project.
to create a virtual environment
$ sudo pip install virtualenv
$ $ virtualenv -p your_python_version my_env_name
also since you are using anaconda you can use conda command like this
$ conda create -n yourenvname python=x.x

Related

Pip does not work in a virtual environment. Fish-Shell,

I use a fish shell, activate a virtual environment, Python works from the environment, but pip is used globally. How to fix it?
$ which python
/develop/venv/bin/python
$ which pip
/usr/bin/pip
$ python -m pip --version
pip 21.1 from /develop/venv/lib/python3.9/site-packages/pip
~ / .pydistutils.cfg The file does not exist.

Are pip and python consistent? Seems like the answer is no. Can someone help me decrypt the documentation?

So i'm trying to implement stripe on a Django app and i'm having issues.
I installed Stripe using pip3 -install stripe and it downloaded. However when I run the server it says
ModuleNotFoundError: No module named 'stripe'
So looking around and on this I think I found some sort of an answer.
https://nomodulenamed.com/a/I-have-installed-the-package-using-pip#fail-to-install
Are pip and python consistent?
Seems like the answer is no.
pip3 -V returned pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
and
python3 -V returned Python 3.8.2
It seems that the easy fix is using python3 -m pip3 -V but that returns No module named pip3
and
python3 -m pip -V returns pip 20.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
but pip -V returns zsh: command not found: pip
which leaves me quite confused
more over i'm suppose to do # install your package
python -m pip <your-package-name>
so what goes in the place of
<your-package-name>
and I'm I suppose to use pip of pip3 since I use pip3 to install thing.
Since you can have more than one Python2 installation and more than one Python3 installation available on your machine, your question is better answered by understanding virtual environments.
It is precisely the reason why virtual environments exist!
when you create a python3 virtual environment there is no need to call pip3 as it is the default pip.
start by creating your virtual env (Assuming you have virtualenv installed ... if not install it on linux ubuntu by calling
sudo apt-get install virtualenv
sudo apt-get install python3-pip
python3 -m venv env
source bin/env/activate
pip install <yourpackage>
but I believe you are on macOS since you are getting zsh error,
fix your installation by using homebrew
brew install python3
pip3 install virtualenv
virtualenv -p python3 <path-to your-project>
source <path-to your-project>/bin/activate

Where are python packages stored in a virtual environment?

I need to find the python packages within my virtual environment.
When I run pip freeze I can see all the packages in the virtual environment.
However, when I cd ./venv/ and run tree Pillow (or manually search) I cannot find any installed package.
Any idea where they are stored?
Ask pip to tell you where it installed the project with the following command:
$ path/to/venv/bin/python -m pip show --files Pillow
from virtualenv do pip -V
It will be in : <virtual env root dir> + lib
example from my terminal
(vams_test) C:\VAMS\jiras\vams>pip -V
pip 19.2.3 from c:\vams\code\copy_v0.1\vams_test\lib\site-packages\pip (python 3.7)

Wrong pip version for anaconda's environments. What should I do to correct the pip version when activate a env using `conda activate`?

I have 4 envs in my anaconda as listed below.
>>> conda info --envs
base /home/gph/anaconda3
py36_torch0.4 * /home/gph/anaconda3/envs/py36_torch0.4
py37_torch1.1 /home/gph/anaconda3/envs/py37_torch1.1
python3.6 /home/gph/anaconda3/envs/python3.6
In both py36_torch0.4 and py37_torch1.1, I did some test.
>>>(py36_torch0.4) gph#gph-1050Ti:~ $ whereis pip
pip: /home/gph/.local/bin/pip3.5
/home/gph/.local/bin/pip
/home/gph/anaconda3/envs/py36_torch0.4/bin/pip3.6
/home/gph/anaconda3/envs/py36_torch0.4/bin/pip
(py36_torch0.4) gph#gph-1050Ti:~ $ pip -V
pip 19.1.1 from /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5)
(py37_torch1.1) gph#gph-1050Ti:~ $ whereis pip
pip: /home/gph/.local/bin/pip3.5
/home/gph/.local/bin/pip
/home/gph/anaconda3/envs/py37_torch1.1/bin/pip
(py37_torch1.1) gph#gph-1050Ti:~ $ pip -V
pip 19.1.1 from /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5)
We can see that for each env_name we have envs/env_name/bin/pip, but the output of pip -V is always /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5).
What is wrong? What should I do to make the pip version right when activate a specific env?
I have tried unset PYTHONPATH as told in this question: Wrong pip in conda env. But it is no use.
Use pip as a module called by the Python interpreter of your env.
python -m pip install some_package where python is the one active on your env, for example /home/gph/anaconda3/envs/python3.6/bin/python.
You've installed pip outside of the conda environments, directly into your home directory. This takes precedence over everything that's installed in conda.
If you want to benefit from isolation of conda environments, you cannot install packages on the user level. This will get rid of all of them (but maybe also some more):
rm -rf /home/gph/.local
You might want to have a look at what else is installed in /home/gph/.local before actually removing it.

Managing python2 and python3 at the same time

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 -Vto 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/

Categories

Resources