Related
Edit:
So now which pip, which python and which python3 have started working correctly somehow. I was also able to install libraries using pip. The only remaining problem is that of the apt_pkg. Running apt-get install python-apt gives:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-apt is already the newest version (1.6.3ubuntu1).
Running any python application still gives error: ImportError: No module named apt_pkg
Running echo $PATH returns:
/home/hamza/bin:/home/hamza/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Running find /usr -name python -o -name python3 returns:
/usr/local/lib/python3.5/dist-packages/notebook/static/components/codemirror/mode/python
/usr/local/lib/python2.7/dist-packages/notebook/static/components/codemirror/mode/python
/usr/lib/python3
/usr/lib/gimp/2.0/python
/usr/lib/libreoffice/share/Scripts/python
/usr/lib/virtualbox/sdk/bindings/xpcom/python
/usr/lib/wx/python
/usr/bin/python
/usr/bin/python3
/usr/share/code/resources/app/extensions/python
/usr/share/bash-completion/helpers/python
/usr/share/bash-completion/completions/python
/usr/share/bash-completion/completions/python3
/usr/share/python
/usr/share/javascript/codemirror/mode/python
/usr/share/python3
/usr/share/lintian/overrides/python
/usr/share/lintian/overrides/python3
/usr/share/gcc-8/python
/usr/share/gdb/python
/usr/share/librevenge/python
/usr/share/doc/python
/usr/share/doc/python3
/usr/share/doc/python-statsmodels/examples/python
/usr/share/playonlinux/python
Original:
Python on my system is a wreck. I have got multiple versions installed. None work properly. Apparently some applications using python are not working either (eg: Unity Tweaks). My python libraries will not install because pip doesn't work, although it says it is already installed
I was trying to install some libraries for python on my system using pip. Turned out pip was not working. I tried to reinstall pip only to learn that pip was already installed. I went through a process of understanding the difference between python and python3. I have tried enough things and have basically lost track of the things I have done to get the libraries installed. Long story short, pip does not work no matter what, my libraries will not install and consequently my code doesn't run.
Here is some of the things I have already done:
which pip
This return no output
apt-get install python-pip
Says I have pip already installed
apt-get install python-apt
To resolve ImportError: No module named apt_pkg. It says:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-apt is already the newest version (1.6.3ubuntu1).
But the error persists
And countless other stuff I do not remember.
What I want now is simple. I wish to somehow get out of this hassle by resetting all of my python settings and installation to default, and then install the pandas and numpy libraries for my system. Any and all help would be appreciated.
Result for python -m pip -V:
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
Result for python3 -m pip -V:
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
One of the following commands worked for me:
pip3 install -U pip
python -m pip install -U pip
python3 -m pip install -U pip
Make sure the version of your python3 is 3.6, which is the default version of ubuntu18, then upgrade pip.
export py3_path=`which python3`
rm $py3_path
ln -s `which python3.6` $py3_path
python3 -m pip install -U pip
Or use pyenv to manage multi versions https://github.com/pyenv/pyenv
That's it, I've some package installed using setuptools i.e. I ran the command python setup.py install from the package source.
My question is, how do I uninstall the package or upgrade it?
Install pip using easy_install:
easy_install pip
and then:
pip uninstall <package>
PS. Probably duplicate.
I've created virtualenv for Python 2.7.4 on Ubuntu 13.04. I've installed python-dev.
I have the error when installing numpy in the virtualenv.
Maybe, you have any ideas to fix?
The problem is SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
so do the following in order to obtain 'Python.h'
make sure apt-get and gcc are up to date
sudo apt-get update
sudo apt-get upgrade gcc
then install the python2.7-dev
sudo apt-get install python2.7-dev
and I see that you have most probably already done the above things.
pip will eventually spit out another error for not being able to write into /user/bin/blahBlah/dist-packages/ or something like that because it couldn't figure out that it was supposed to install your desiredPackage (e.g. numpy) within the active env (the env created by virtualenv which you might have even changed directory to while doing all this)
so do this:
pip -E /some/path/env install desiredPackage
that should get the job done... hopefully :)
---Edit---
From PIP Version 1.1 onward, the command pip -E doesn't work. The following is an excerpt from the release notes of version 1.1 (https://pip.pypa.io/en/latest/news.html)
Removed -E/--environment option and PIP_RESPECT_VIRTUALENV; both use a restart-in-venv mechanism that's broken, and neither one is useful since every virtualenv now has pip inside it. Replace pip -E path/to/venv install Foo with virtualenv path/to/venv && path/to/venv/pip install Foo
If you're on Python3 you'll need to do sudo apt-get install python3-dev. Took me a little while to figure it out.
If you're hitting this issue even though you've installed all OS dependencies (python-devel, fortran compiler, etc), the issue might be instead related to the following bug:
"numpy installation thru install_requires directive issue..."
Work around is to manually install numpy in your (virtual) environment before running setup.py to install whatever you want to install that depends on numpy.
eg, pip install numpy then python ./setup.py install
This answer is for those of us that compiled python from source or installed it to a non standard directory. In my case, python2.7 was installed to /usr/local and the include files were installed to /usr/local/include/python2.7
C_INCLUDE_PATH=/usr/local/include/python2.7:$C_INCLUDE_PATH pip install numpy
I recently had the same problem. I run Debian Jessie and tried to install numpy from a Python 2.7.9 virtualenv. I got the same error -- numpy complaining that Python.h is missing while python2.7-dev and gcc are already installed.
File "numpy/core/setup.py", line 42, in check_types
],
File "numpy/core/setup.py", line 293, in check_types
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
I'm running pip 1.5.6 and it doesn't appear to have command line option '-E'
$ pip -V
pip 1.5.6 from /home/alex/.virtualenvs/myenv/local/lib/python2.7/site- packages (python 2.7)
Upgrading pip to the latest verson 7.0.3 solves the problem
$ pip install --upgrade pip
Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.0.3-py2.py3-none-any.whl#md5=6950e1d775fea7ea50af690f72589dbd
Downloading pip-7.0.3-py2.py3-none-any.whl (1.1MB): 1.1MB downloaded
Installing collected packages: pip
Found existing installation: pip 1.5.6
Uninstalling pip:
Successfully uninstalled pip
Successfully installed pip
Cleaning up...
Now it is possible to install numpy
$ pip install numpy
Collecting numpy
Downloading numpy-1.9.2.tar.gz (4.0MB)
100% |████████████████████████████████| 4.0MB 61kB/s
Installing collected packages: numpy
Running setup.py install for numpy
Successfully installed numpy-1.9.2
This is probably because you do not have the python-dev package installed. You can install it like this:
sudo apt-get install python-dev
You can also install it via the Software Center:
#samkhan13 solution didn't work for me as pip said it doesn't have the -E option.
I was still getting the same error, but what worked for me was to install matplotlib, which installed numpy.
I'm having troubles with installing packages in Python 3.
I have always installed packages with setup.py install. But now, when I try to install the ansicolors package I get:
importerror "No Module named Setuptools"
I have no idea what to do because I didn't have setuptools installed in the past. Still, I was able to install many packages with setup.py install without setuptools. Why should I get setuptools now?
I can't even install setuptools because I have Python 3.3 and setuptools doesn't support Python 3.
Why doesn't my install command work anymore?
Your setup.py file needs setuptools. Some Python packages used to use distutils for distribution, but most now use setuptools, a more complete package. Here is a question about the differences between them.
To install setuptools on Debian:
sudo apt-get install python3-setuptools
For an older version of Python (Python 2.x):
sudo apt-get install python-setuptools
EDIT: Official setuptools dox page:
If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from
python.org, you will already have pip and setuptools, but will need to
upgrade to the latest version:
On Linux or OS X:
pip install -U pip setuptools
On Windows:
python -m pip install -U pip setuptools
Therefore the rest of this post related to Distribute is obsolete (e.g. some links don't work).
EDIT 2022-02-04
From Python 3.10 Distutils is deprecated and will be removed in Python 3.12 - use setuptools:
The entire distutils package is deprecated, to be removed in Python 3.12. Its functionality
for specifying package builds has already been completely replaced by
third-party packages setuptools and packaging ...
Distribute (deprecated)
Distribute - is a setuptools fork which "offers Python 3 support". Installation instructions for distribute(setuptools) + pip:
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
Similar issue here.
UPDATE: Distribute seems to be obsolete, i.e. merged into Setuptools: Distribute is a deprecated fork of the Setuptools project. Since the Setuptools 0.7 release, Setuptools and Distribute have merged and Distribute is no longer being maintained. All ongoing effort should reference the Setuptools project and the Setuptools documentation.
You may try with instructions found on setuptools pypi page (I haven't tested this, sorry :( ):
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
easy_install pip
Make sure you are running the latest version of pip
I tried to install Ansible and it failed with
ModuleNotFoundError: No module named 'setuptools_rust'
python3-setuptools was already in place, so upgrading pip solved it.
pip3 install -U pip
I was doing this inside a virtualenv on Oracle Linux 6.4 using Python 2.6, so the apt-based solutions weren't an option for me, nor were the Python 2.7 ideas. My fix was to upgrade my version of setuptools that had been installed by virtualenv:
pip install --upgrade setuptools
After that, I was able to install packages into the virtualenv.
The solution which worked for me was to upgrade my setuptools:
python3 -m pip install --upgrade pip setuptools wheel
For others with the same issue due to a different reason: This can also happen when there's a pyproject.toml in the same directory as the setup.py, even when setuptools is available.
Removing pyproject.toml fixed the issue for me.
pip uninstall setuptools
and then:
pip install setuptools
This works for me and fixes my issue.
When there's a pyproject.toml in the same directory as the setup.py, it can be the cause of the issue. I renamed that file, but it didn't solve the issue, so I restablished the original file name, and did the following change.
Under the [build-system] section, I added "setuptools" to the requires= list, and it worked.
First step #1
You have to install setuptools
On Linux:
pip install -U pip setuptools
On Mac OS:
pip install -U pip setuptools
On Windows:
python -m pip install -U pip setuptools
Second step #2
Make sure you have made it accessible (make it available in environmental variables)
On Linux
export PATH="INSTALLATIONDIRECTORY:$PATH"
On Mac OS
Sorry, I don't know.
On Windows
Open the Start Search, type in “env”, and choose “Edit the system environment variables”
Click the “Environment Variable” button.
Set the environment variables as needed. The New button adds an additional variable.
Dismiss all of the dialogs by choosing “OK”. Your changes are saved!
The distribute package provides a Python 3-compatible version of setuptools: http://pypi.python.org/pypi/distribute
Also, use pip to install the modules. It automatically finds dependencies and installs them for you.
It works just fine for me with your package:
[~] pip --version
pip 1.2.1 from /usr/lib/python3.3/site-packages (python 3.3)
[~] sudo pip install ansicolors
Downloading/unpacking ansicolors
Downloading ansicolors-1.0.2.tar.gz
Running setup.py egg_info for package ansicolors
Installing collected packages: ansicolors
Running setup.py install for ansicolors
Successfully installed ansicolors
Cleaning up...
[~]
this is how my problem was solved => pip3 install setuptools-rust
If you want to check your list => pip3 list
i faced this problem while trying to install elastalert2
System informations
CentOS Linux release 7.9.2009 (Core)
Python 3.6.8
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
I ran into this problem when my pip requirements.txt file contained an editable library that was built using poetry and contained a pyproject.toml file. Following the documentation for setuptools, my solution was to add setuptools to the build-system requirements in the pyproject.toml file as follows:
[build-system]
requires = ["poetry-core>=1.0.0", "setuptools"]
build-backend = "poetry.core.masonry.api"
If pip isn't installed, like for example if it's coming from the Deadsnakes PPA, or a Docker environment, the best way to fix this error is by bootstrapping it by running
python -m ensurepip
Windows 7:
I have given a complete solution here for Python Selenium WebDriver:
Setup easy install (Windows - simplified)
download ez.setup.py (https://bootstrap.pypa.io/ez_setup.py) from 'https://pypi.python.org/pypi/setuptools'
move ez.setup.py to C:\Python27\
open cmd prompt
cd C:\Python27\
C:\Python27\python.exe ez.setup.py install
I ran sudo python setup.py build_ext -i and it failed with No module named setuptools.
I solved it with this command:
<i>sudo apt-get install python-setuptools</i>
A few years ago I inherited a Python (2.7.1) project running under Django-1.2.3 and now was asked to enhance it with QR possibilities. I got the same problem and did not find pip or apt-get either. So I solved it in a totally different, but easy way.
I /bin/vi-ed the setup.py and changed the line
"from setuptools import setup"
into:
"from distutils.core import setup"
The PyPA recommended tool for installing and managing Python packages is pip. pip is included with Python 3.4 (PEP 453), but for older versions here's how to install it (on Windows):
Download https://bootstrap.pypa.io/get-pip.py
>c:\Python33\python.exe get-pip.py
Downloading/unpacking pip
Downloading/unpacking setuptools
Installing collected packages: pip, setuptools
Successfully installed pip setuptools
Cleaning up...
>c:\Python33\Scripts\pip.exe install pymysql
Downloading/unpacking pymysql
Installing collected packages: pymysql
Successfully installed pymysql
Cleaning up...
On macOS, if you have homebrew installed, simply run:
brew install rust
If you still find this issue, try this:
python3 -m pip install scrapy --upgrade --force --user
While trying to install socketIO I had the same issue. At my system (Windows 11) setupTools were there twice. At C:\Program Files\Python310\Lib\site-packages\ and at C:\Users\user\AppData\Roaming\Python\Python310\site-packages\
Had to uninstall one of them.
Working on Debian, sometime it can be because of older pip version. Therefore, update pip>
python -m pip install -U pip
I had such a problem to install pyunicorn. I wanted to install it on Google Colab. I tried installing pyunicorn directly from Github and it worked for me. For example in my case it was like this:
pip install git+https://github.com/pik-copan/pyunicorn.git#egg=pyunicorn
I am trying to set up a PostgreSQL database for my django project, which I believe I have done now thanks to the replies to my last question Problems setting up a postgreSQL database for a django project. I am now trying to run the command 'python manage.py runserver' in Terminal to get my localhost up but when I run the command, I see this response...
Error: No module named psycopg2.extensions
I'm not sure what this means - I have tried to download psycopg2 but can't seem to find a way to download psycopg2 using homebrew. I have tried easy_install, pip install and sudo but all return errors like this...
Downloading http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz
Processing psycopg2-2.4.5.tar.gz
Writing /tmp/easy_install-l7Qi62/psycopg2-2.4.5/setup.cfg
Running psycopg2-2.4.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-l7Qi62/psycopg2-2.4.5/egg-dist-tmp-PBP5Ds
no previously-included directories found matching 'doc/src/_build'
unable to execute gcc-4.0: No such file or directory
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1
How to fix this?
The first thing to do is to install the dependencies.
sudo apt-get build-dep python-psycopg2
sudo apt install python3-psycopg2 # Python 3
After that go inside your virtualenv and use:
pip install psycopg2-binary
These two commands should solve the problem.
pip install psycopg2-binary
The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.
For Django 2 and python 3 install psycopg2 using pip3 :
pip3 install psycopg2
I installed it successfully using these commands:
sudo apt-get install libpq-dev python-dev
pip install psycopg2
For macOS Mojave just run pip install psycopg2-binary. Works fine for me, python version -> Python 3.7.2
first install apt-get install python-setuptools
then try easy_install psycopg2
This is what helped me on Ubuntu if your python installed from Ubuntu installer. I did this after unsuccessfully trying 'apt-get install' and 'pip install':
In terminal:
sudo synaptic
then in synaptic searchfield write
psycopg2
choose
python-psycopg2
mark it for installation using mouse right-click and push 'apply'. Of course, if you don't have installed synaptic, then first do:
sudo apt-get install synaptic
I ran into this same issues recently and this code worked.
sudo apt-get install libpq-dev python-dev-is-python3
Then
pip3 install psycopg2
In python 3.4, while in a virtual environment, make sure you have the build dependencies first:
sudo apt-get build-dep python3-psycopg2
Then install it:
pip install psycopg2
On Alpine Linux (majority of the docker containers) do:
apk add postgresql-dev
Then:
pip install psycopg2-binary
pip3 install django-psycopg2-extension
I know i am late and there's lot of answers up here which also solves the problem. But today i also faced this problem and none of this helps me. Then i found the above magical command which solves my problem :-P . so i am posting this as it might be case for you too.
Happy coding.
I used the extension after only importing psycopg2:
import psycopg2
...
psycopg2.extensions.AsIs(anap[i])
It seems that you need gcc-4.0, and it would be helpful to specify your OS type and version.
Maybe this question will help you a bit: Installing GCC to Mac OS X Leopard without installing Xcode
Update
I'm a Windows user, so I can't test your setup, but a quick google pointed to some more links:
http://hardlifeofapo.com/psycopg2-and-postgresql-9-1-on-snow-leopard/
Cannot install psycopg2 on OSX 10.6.7 with XCode4
I encountered the No module named psycopg2.extensions error when trying to run pip2 install psycopg2 on a Mac running Mavericks (10.9). I don't think my stack trace included a message about gcc, and it also included a hint:
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
I looked for the pg_config file in my Postgres install and added the folder containing it to my path: /Applications/Postgres.app/Contents/Versions/9.4/bin. Your path may be different, especially if you have a different version of Postgres installed - I would just poke around until you find the bin/ folder. After doing this, the installation worked.
try this: sudo pip install -i https://testpypi.python.org/pypi psycopg2==2.7b2
.. this is especially helpful if you're running into egg error
on aws ec2 instances if you run into gcc error; try this
1. sudo yum install gcc python-setuptools python-devel postgresql-devel
2. sudo su -
3. sudo pip install psycopg2
This one worked for me
python manage.py migrate
I had such problem when trying to run python script as a sudo, while psycopg2 was installed via pip3 to my own user's directory.
I managed to resolve the issue for myself removing pip3 version, and just installing it via apt:
pip3 uninstall psycopg2
sudo apt install python3-psycopg2
you can install gcc for macos from https://github.com/kennethreitz/osx-gcc-installer
after instalation of gcc you'll be able to install psycopg with easy_install or with pip
Check if you have installed psycopg2 if not
sudo apt-get install psycopg2
Install the dependencies.
sudo apt-get build-dep python-psycopg2
These two commands should solve the problem.
This error raise because you not install postgres database in you project virtutal environment. you should run one of these command.
from a terminal you can you command for sudo.
sudo apt-get install build-dep python-psycopg2
for pip (pip basically work for python)
pip install psycopg2
or
pip3 install psycopg2-binary
i'm pretty sure it will work for you.