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.
Related
Creation of venv with python3 is ok.
However, when I run pip install requests in the venv, the package has been installed in the normal python site-package outside of the venv.framework folder. The pip doesn't install package in the venv.
I've installed python3 from brew.
I've installed python3.9 and python3.10, which are downloaded from the python homepage.
Outside of the venv, the 'which' command looks like this.
which python
/usr/local/bin/python
which python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
which python3.9
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
which python3.10
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10
which pip
pip: aliased to /usr/local/bin/pip3
which pip3
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
which pip3.9
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9
which pip3.10
/Library/Frameworks/Python.framework/Versions/3.10/bin/pip3.10
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Inside of the venv:
which python
/....../venv_test/venv/bin/python.
which python3
/....../venv_test/venv/bin/python3
which python3.9
/....../venv_test/venv/bin/python3.9
which python3.10
/....../venv_test/venv/bin/python
which pip
pip: aliased to /usr/local/bin/pip3
which pip3
/....../venv_test/venv/bin/pip3
which pip3.9
/....../venv_test/venv/bin/pip3.9
which pip3.10
/....../venv_test/venv/bin/pip3.10
echo $PATH
/....../venv_test/venv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Please help.
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.
strugging to get pip install working with virtualenv.
$ virtualenv env
$ source env/Scripts/activate
I now have two python installations:
(env) $ where python
D:\my_folder\env\Scripts\python.exe
C:\Users\Me\Anaconda3\python.exe
I am using the one I want:
(env) $ which python
D:\my_folder\env\Scripts\python.exe
Same with pip:
(env) $ where pip
D:\my_folder\env\Scripts\pip.exe
C:\Users\Me\Anaconda3\Scripts\pip.exe
(env) $ which pip
D:\my_folder\env\Scripts\pip.exe
However I have the following
(env) $ pip -V
pip 18.0 from C:\Users\Me\Anaconda3\Lib\site-packages\pip (python 3.6)
wrong place!
(env) $ pip freeze
... dumps out my global packages!!
(env) $ pip install requirements.txt
... fails because requirements cannot be met.
I have a feeling that I have bad environment variable somewhere but don't really know where to look?! I'm just coming over from node and npm and finding python modules to be a bit of a car crash (although the language is awesome). Anyhow all help appreciated.
(EDIT)
OK, so (thanks to #alec_djinn) the following works:
python -m pip install requirements.txt
however
python -m pip freeze
still dumps my global installations.
I have both the version of python.I have also installed jupyter notebook individually and when i open the jupyter notebook and go to new section it is showing python 2
I want to use python3 for newer packages.So how can we upgrade the python version.
More systematic approach would be
1 Install virtualenvwrapper
$ pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv -p $(which python3) jupyter_notebook
2 Install jupyter in this environment
(jupyter_notebook)$ pip install jupyter
3 Run notebook
(jupyter_notebook)$ jupyter notebook
4 To install new packages don't forget to activate newly created virtual environment
$ workon jupyter_notebook
(jupyter_notebook)$ pip install numpy
If the kernel was not visible in the kernel options you will have to configure it manually. This is how I did it on my macos.
python3 -m pip install ipykernel
python3 -m ipykernel install --user
After running these commands you should be able to see the kernel in the change kernel option.
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