Unable to install pip on Ubuntu 14.04 - python

On my Ubuntu 14.04 machine, when I try to install boto3 I get
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip import main
ImportError: No module named pip
I then try to install pip using sudo apt install python-pip and I get
Reading package lists... Done
Building dependency tree
Reading state information... Done
...
0 upgraded, 0 newly installed, 0 to remove and 130 not upgraded.
I then try and install pip using the directions here but when I run
python get-pip.py
I get
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7.9/lib/python2.7/site-packages/pip'
Consider using the `--user` option or check the permissions.
Is the website I linked an appropriate way of installing pip, and if so how do I resolve my permissions error? I'm using python 2.7.9.

Install conda (the best: miniconda - since more lightweight than Anaconda).
This you do by going to this site: https://docs.conda.io/en/latest/miniconda.html
Take care, which OS and whether 32bit or 64bit.
E.g. Linux 32 bit
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86.sh
Or Linux 64 bit
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
And for installation you do:
bash Miniconda3-latest-Linux-x86.sh
or
bash Miniconda3-latest-Linux-x86_64.sh
, respectively, in the terminal.
After that, any command starting with conda in terminal will work.
conda solves such dependency problems you have now.
create an environment useful for this stuff
conda create --name myenv
conda activate myenv # enter then newly created environment
Then, installing pip is super easy:
# the new environment e.g. here, <myenv>
conda install pip # this installs automatically newest Python and pip
# you could also do:
conda install git pip
# if you also want to pip install directly from github repositories

Related

I used pip3 to install virtualenv but I can't create venv and also I can't uninstall virtualenv

I'm using Linux Mint 20.2 with two directories / and /home.
I used the following command to install virtualenv:
>>> sudo pip3 install virtualenv
It worked fine and it installed in the following path:
>>> virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
But when I tried to create an environment I got the following error:
>>> python3 -m venv article
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt install python3.8-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/username/article_tools/article/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
When I tried to uninstall it to install it using [b]sudo apt install python3.8-venv[/b], I got the following error:
>>> sudo pip3 uninstall virtualenv
Found existing installation: virtualenv 20.0.17
Not uninstalling virtualenv at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'virtualenv'. No files were found to uninstall.
How can I fix it? By fix, I mean installing virtualenv in a way that I don't get such errors.
The fundamental problem here seems to be that you are mixing up two different packages.
Python 3 comes with a built-in virtual environment module venv which is however not installed by default on Debian-based platforms. Like the error message says, apt-get install -y python3-venv will install this package, which you can then use with python3 -m venv.
virtualenv is a separate third-party package which you invoke with the command virtualenv. It's not a bad alternative, but if you are only just learning, I would suggest you simply ignore it for the time being.

Pip not installing packages without --user on my own laptop

Recently I messed up my steady environment by installing multiple versions of python.
What I'm trying to do: install a particular package using pip
pip cannot install any package without the --user tag
Could not install packages due to an EnvironmentError: [Errno 13 Permission denied: '/Library/Python/2.7/site-packages/PIL
Here's More information:
which pip
/usr/local/bin/pip
which python
/usr/bin/python
What should I do?
Use sudo or su to install packages system-wide.

Pipenv-Error: ModuleNotFoundError: No module named 'pip._internal' [duplicate]

This question already has answers here:
pip: no module named _internal
(30 answers)
Closed last month.
Today, I installed Pipenv via
pip install pipenv
As mentioned in the documentation I went to a test directory and created a new virtual environment using
pipenv shell
and tried to install a package via
pipenv install numpy
I got the following error message:
Installing numpy…
⠧
Error: An error occurred while installing numpy!
Traceback (most recent call last):
File "/Users/florian/.local/share/virtualenvs/test-bJfQ6Jzk/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
This error occurs even after reinstalling pipenv, deleting all files and recreate the environment. It also had no impact if I ran pipenv install numpy inside or outside the environment.
Python 3.6.3
Pipenv 11.10.1
Thank you in advance.
I have had the same issue (python 3.5/Ubuntu 16.04LTS). Reinstalling pip with:
sudo apt install python-pip python-pip3 --reinstall
didn't solve the issue with me.
What worked in my case was reinstalling pipenv itself, from pip:
sudo pip3 install pipenv --force-reinstall
If you are running python 2.x or if your system is different than mine, you can try to replace pip3 with pip in the command:
sudo pip install pipenv --force-reinstall
Ubuntu 18.04, Python 3.6 :
Reinstalling pipenv did not work for me. Reinstall pip3 was the only issue, but
sudo apt install python3-pip
did not work too. Found a link to get pip3 in AskUbuntu.com which worked fine :
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py --force-reinstall
After trying around for a while, I fully reinstalled pip. This solved the problem and everything is working now as expected.
Before providing the two commands, which solved the problem, I want to specify some things:
I'm on MacOS
python stands for python3 (added an alias for that, because I only use python3)
pip is on version 9 and NOT 10
Here are both commands:
sudo pip uninstall pip
sudo python get-pip.py
I resolved problem using this command:
pip3 install pipenv --upgrade
The environment pipenv is trying to use may be corrupt for the current project.
Removing it, and re-running pipenv install worked in my case. I am on Fedora 35, where the python virtualenvs are located in ~/.local/share/virtualenvs/, this may be different in your case.
find out which virtualenvs are on your disk:
ls ~/.local/share/virtualenvs/
remove the ones belonging to your project:
rm -rf ~/.local/share/virtualenvs/yourprojectname*

install pip3 for conda

Python2.6 was installed by default in my old centos server. Now I want to create a Python3 environment to install python3 specific module by conda
conda create -n py3 python=3.5.3
source activate py3
After activate the py3, I try to install hovercraft by pip3 install hovercraft, the shell tells "command not found: pip3". At first I thought pip3 was installed with Python3, but the result was not the case.
So I think I can install it manually. The package gzip file was downloaded from python package index, and install by conda install --file hovercraft-2.3.tar.gz. But it doesn't work.
Now I have two problems:
how to install pip3 for virtual-env create by conda?
Is it possible to install python package index downloaded package locally in conda?
pip3 and pip would make a difference only when you are not using any environment managers like virualenv (or) conda. Now as you are creating a conda environment which has python==3.x, pip would be equivalent to pip3.

Python GDAL package missing header file when installing via pip

I'm trying to install gdal from pip pip install gdal inside a virtual environment (Ubuntu). It fails because it cannot find cpl_port.h
extensions/gdal_wrap.cpp:2853:22: fatal error: cpl_port.h: No such file or directory
compilation terminated
However GDAL is installed correctly and the header file is located at /usr/include/gdal/cpl_port.h. Is there some environment variable for GDAL that needs to be set in order for pip to find the header files?
As suggested in the other thread, exporting some shell variables before running pip worked flawlessly. A path for *_INCLUDE_PATH can be found with gdal-config --cflags.
# GDAL library must have been installed
sudo apt-get install libgdal-dev
# Set up pip and/or virtualenv stuff
...
# Now install Python binding for GDAL
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip install GDAL
Tomyun's answer worked for me, with the proviso that you have to ensure that the version of GDAL-dev installed via apt-get matches the version being installed by pip.
For Ubuntu 14.04, the commands are:
# GDAL library must have been installed
sudo apt-get install libgdal-dev
# Set up pip and/or virtualenv stuff
...
# Now install Python binding for GDAL
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip3 install GDAL=1.10.0
Taken from this comment, it solved my issue directly
pip3 install GDAL==$(gdal-config --version)
Explicit version number should match your existing libgdal version. –
Using PIP :
pip install --no-install GDAL
Then cd into ENV/build/GDAL
python setup.py build_ext --include-dirs=/usr/include/gdal
pip install --no-download GDAL
(Source: http://ubuntuforums.org/showthread.php?t=1769445)
Using Buildout :
[gdal-bindings]
recipe = zc.recipe.egg:custom
egg = GDAL==1.9.1
include-dirs = /usr/include/gdal
library-dirs = /usr/lib
I was also getting this error when test installing in a virtual environment a package of mine that depends on GDAL. In this case the solution is to change the dependecy from GDAL to pygdal in the install_requires parameter in setup.py. Like so:
install_requires=['pygdal'],
This is what worked for me:
I had to get the latest hearder versions for installing gdal 2.2.4 through pip:
sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install libgdal-dev
Before that, I was getting extensions/gdal_wrap.cpp:3172:27: fatal error: cpl_vsi_error.h: No such file or directory, even when including the correct "include" path to pip.
The the pip installation (in a virtualenv):
pip install --global-option=build_ext --global-option="-I/usr/include/gdal" gdal
try to do:
brew install gdal
after that try again.

Categories

Resources