python virtual env somehow using wrong pip - python

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.

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.

pip fails in my python virtual environments

Trying to follow this tutorial: https://docs.python.org/3/tutorial/venv.html.
$ python3 -m venv tutorial-env
$ source tutorial-env/bin/activate
so far so good, however:
(tutorial-env) $ pip --version
import: not authorized `re' # error/constitute.c/WriteImage/1028.
import: not authorized `sys' # error/constitute.c/WriteImage/1028.
from: can't read /var/mail/pip
~/src/examples/tutorial-env/bin/pip: line 10: syntax error near unexpected token `('
~/src/examples/tutorial-env/bin/pip: line 10: ` sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])'
tells me something must be wrong with my python installation. I assume that should have worked.
Some information about my system installation, and the version of the software used to create that tutorial-env environment:
(tutorial-env) $ deactivate
$ which python3 && python3 --version
/usr/bin/python3
Python 3.5.2
$ python3 -m pip --version
pip 20.2.3 from ~/.local/lib/python3.5/site-packages/pip (python 3.5)
That does not seem right to me. Perhaps the problem is rooted in /usr/bin/python3 -m pip using dependencies under ~/.local/lib when I would have expected it to depend on /usr/local/lib/python3.5/dist-packages/pip. I'm not entirely sure this is the root cause though, perhaps I just don't know how to start a virtual environment.
Update: Looking carefully, I see that /usr/local/lib/python3.5/dist-packages does not contain a pip folder, whereas /usr/local/lib/python2.7/dist-packages by comparison does. Perhaps that is the root cause. However I have installed python3-pip via apt-get install.
Try re-installing both python and the virtual environment in that order

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

How to resolve between two python 3 installations?

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

How to install a module to one of many pythons in Fedora 20

I have on my Fedora 20 additionally to 2.7 a python3.6 version installed.
When I run a script with the 3.6 version it's missing the requests module.
When I try to install it with the pip command it says it's already there.
So, how can I install this module in python3.6?
Any hints?
Thanks
Check if pip36 or more likely pip3 is a function you can run. Often times the pip command corresponds to the first installed python version, so if you install one later it gets the suffix according to its version. If that is the case then you'll want to do pip36 (pip3) install moduleXYZ.
Quick and dirty answer is
For python2,x install any package using pip install requests
For python 3.x install any package using pip3 install requests
If you get error during pip3 please run sudo dnf install python3-pip
But the right way is to do it using Virtual Environment in fedona
For py3.4+
$ python3.5 -m venv env # create the virtualenv
$ . env/bin/activate # activate it
(env)$ python -m pip install requests # install a package with pip
For py2.x, 3.x
$ dnf install python-virtualenv # install the necessary tool
$ virtualenv --python /usr/bin/python2.7 env # create the virtualenv
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in env/bin/python2.7
Also creating executable in env/bin/python
Installing setuptools, pip...done.
$ . env/bin/activate # activate it
(env)$ python -m pip install requests # install a package with pip
Refrence

Categories

Resources