what where and how of pip when mixed with virtual environments - python

What i think i know currently is this:
The way to install pip is sudo apt-get install python-pip
sudo apt-get install python-pip installs pip at '/usr/lib/python3/dist-packages'
pip install abc installs abc to virtualenv where pip that gets called is
I use conda, and i have an environment 'env' created with it for some time now. I needed to install a package that said i needed pip3 > 19.0.1 so i which pip and it was 9.0.2 and it was well within the environment. i updated the pip using python -m pip install --upgrade pip and it got upgraded to 20.0.2. I am happy. However, which pip3 gives me global location, version 9.0.2 and the package i am going to be installing requires pip3 install .. command and conda install pip3 doesn't exist
questions:
How do i install pip3 in a conda environment?
Supposing i did not have conda install pip or let us say i had a non conda virtualenv created, how do i go about installing a pip in this environment so that pip install ... does not install to global location?

Related

Problem with pip, cant install modules from cmd

I just get a syntax error. I've tried these commands:
pip install opencv-python
pip3 install opencv-python
python -m pip install opencv-python
All of these just give me a syntax error.
Trying to install opencv for some webcams, going to be messing with raspberry later.
If you are on Windows you have just to type py -m pip install opencv-python.
If you are on a Linux distribution you should firstly install python-pip or python3-pip (via your package manager) and then type:
pip (or pip3) install opencv-python (if you want to install it locally).
sudo pip (or pip3) install opencv-python (if you want to install it globally).
You can find more information here.

Pip Install keeps installing libraries to Python2.7 rather than Python3

I'm trying to install modules such as gitpython into my Python3 directory however when I run:
Pip install gitpython it automatically downloads it into python2.7
I've tried specify the Python3 directory but it says the the library has already been installed.
Requirement already satisfied: gitpython in /usr/local/lib/python2.7/dist-packages (2.1.11)
Problem is when I try to call from git import repo my Python3 can't find the module.
Is there anyway to get pip to install my libraries to Python3 as a default, can I just uninstall Python 2.7 to save problems?
I run
sudo apt install python3-pip
and it states it is already installed, so I run sudo pip3 install gitpython and it says Command 'pip3' not found, but can be installed with:
sudo apt install python3-pip
SOLUTION
sudo apt-get remove python3-pip; sudo apt-get install python3-pip
It depends of your version of pip. But I think that python3-pip may do the trick.
sudo apt-get install python3-pip
sudo pip3 install MODULE_NAME
You should use pip3 to install your packages in your python3 environment. thus instead of installing with pip use pip3 install gitpython
You can try to see the version of python with:
python --version
if the result is python 2.7, that means that your environment variable for python3 needs to be set.
After that you can try:
python -m pip install package_name
I hope it will help you =)
Adrien
You should use python3 venv Python 3 venv
python3 -m venv /path/virtual/environment
source /path/virtual/environment/bin/activate
or use pip3 to installing any libraries for python 3
$ pip3 install 'some library'
You should create virtual environment for python3. using:
virtualenv -p /usr/bin/python3 <VIRTUAL_ENV NAME>
Then activate it using:
source <VIRTUAL_ENV NAME>/bin/activate
Then install your dependency(gitpython in your case) into that.

Cannot install pip3. apt says I have it, but I can't find it

I am trying to install some pip packages on an Ubuntu 18.4 (For python3) I see if pip is even installed
>/home/me/pip3
Command 'pip3' not found, but can be installed with:
sudo apt install python3-pip
So I do that and I get this:
>/home/me/sudo apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (9.0.1-2.3~ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.
I try whereis for pip:
>/home/me/whereis pip
pip: /usr/local/bin/pip /usr/local/bin/pip2.7 /opt/jython2.7.0/bin/pip /opt/jython2.7.0/bin/pip2.7
and for pip3:
>/home/me/whereis pip3
pip3: /usr/share/man/man1/pip3.1.gz
Why do I have the man pages for it? This makes no sense to me. Any Ideas?
UPDATE
In answer to the first 3 comments
#Mad Physicist Yes it's in my path, and version get's me:
pip 19.0.3 from /home/me/.local/lib/python3.6/site-packages/pip (python 3.6)
Why is it there?
#KuboMD I get this:
>/home/me/python -m pip install xyz
Collecting xyz
Could not find a version that satisfies the requirement xyz (from versions: )
No matching distribution found for xyz
#amitr I get this:
>/home/me/which pip
/usr/local/bin/pip
but that one in my usr/local/bin
From you pip --version output, I assume you have made some upgrades to pip, probably using pip install --upgrade pip --user command, because 19.0.3 is the version you get when upgrading pip via pip. On Ubuntu, both pip2 and pip3 have package version 9.0.1 as you can see here:
https://packages.ubuntu.com/bionic/python3-pip
https://packages.ubuntu.com/bionic/python-pip
It appears that location of your pip is /home/me/.local/lib/python3.6/site-packages/pip. This is where python programs/modules end up, when they are installed via pip install --user option. From that --version output, you can see that your current default pip is actually pip3 because version outputs that it's for (python 3.6), i.e. pip that installs packages for python3.6.
Try listing what other pip binaries you have in your /home/me/.local/bin with command:
ls /home/me/.local/bin/pip*
You should see pip3 and probably pip3.6 there as well.
If there is pip3 executable there a solution would be adding /home/me/.local/ to you PATH environment variable, so that pip3 is callable directly from your shell.

pip is a package and cannot be directly executed

Im trying to install google assistant on my Raspberry Pi, but when I keep getting an error: pip is a package and cannot be directly executed
Instead of
pip [...]
Try doing
python -m pip [...]
Can't really help more without more info.
I think your version of pip is old. You need to upgrade it first, like this:
pip install -U pip
You may need to upgrade setuptools too:
pip install -U setuptools
Since google-assistant-library is available as a wheel, you need to install wheel too:
pip install wheel
I don't know if you can do that with Raspberry Pi, but I recommend you to used a virtualenv. That way, you have a fresh and isolated Python executable and a recent version of pip.
virtualenv your_proj
source your_proj/bin/activate
pip install wheel
pip install google-assistant-library
For newer version ie. using pip3:
pip3 install -U <<package name>>
I had the same problem.
I think it was an outcome of a failed
> .\python.exe -m pip install --upgrade pip
do to some environment misconfiguration.
So it first removed the existing version 10.0.1, and then the installation of the new version 22.3.1 failed, leaving me with no pip.
From official documentation, I ran
> .\python.exe -m ensurepip --upgrade
which restored the original pip 10.0.1.
Then I fixed the environment problem, and then again
> .\python.exe -m pip install --upgrade pip
I now have pip 22.3.1.

is there an uninstall equivalent to "pip install --user <package>"?

Our sysadmin has installed a package, so I can remove my local copy. I'd like to say
pip uninstall --user <package>
but pip uninstall does not support --user. (At least pip 1.5.4 on Linux doesn't.)
Is there an easy way to do this by hand, i.e., delete the directory that contains the package?
This was a known bug in pip
Ref : https://github.com/pypa/pip/issues/2094
As pip uninstall does not have --user option unlike pip install the question is if there even exists a way to uninstall package installed with pip install --user?
It is now cleared with a note
The packages mentioned in the ticket started working after they offered Wheel-based packages.
I have found that upgrading the package first will let you uninstall the package that you installed with --user option. For my case was elevated:
I have installed with command:
pip3 install --user elevate
When i try to uninstall i recieve the skip info:
Skipping elevate as it is not installed.
After many unsuccessfull commands i have found that i need to update the package first with:
pip3 install --user --upgrade elevated
Then i was able to successfully uninstall the elevate package:
pip3 uninstall elevated

Categories

Resources