Terminal command :
python -V output: Python 3.5.2
I'm trying pip and setuptools update on pycharm but this error occurred :
Error :python packaging tool 'pip' not found.
Proposed solution:
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at '/usr/bin/python3.5'.
Terminal command :
which pip output: usr/bin/pip
And I'm trying on terminal command :
pacman -S(or -Syu,-Syy) python-pip or pacman -S(-Syu,-Syy) python-setuptools
resolving dependencies...
looking for conflicting packages...
Packages (5) python-packaging-16.7-1 python-pyparsing-2.1.5-1
python-setuptools-1:24.0.2-1 python-six-1.10.0-2
python-pip-8.1.2-1
Total Installed Size: 8.03 MiB
:: Proceed with installation? [Y/n] y
(5/5) checking keys in keyring [######################] 100%
(5/5) checking package integrity [######################] 100%
(5/5) loading package files [######################] 100%
(5/5) checking for file conflicts [######################] 100%
error:failed to commit transaction (conflicting files)
python-setuptools: /usr/bin/easy_install exists in filesystem
python-setuptools: /usr/bin/easy_install-3.5 exists in filesystem
python-pip: /usr/bin/pip exists in filesystem
python-pip: /usr/bin/pip3 exists in filesystem
python-pip: /usr/bin/pip3.5 exists in filesystem
Errors occured, no packages were upgraded.
So I'm trying :
python -m pip install -U pip
Output :
/usr/bin/python: No module named pip
How to update pip ?
This should work:
pacman -S --force python-pip and pacman -S --force python-setuptools
It's not recommended to install python packages along with pacman. because pacman doesn't recognize any package installed by pip. I think you should remove all pip packages instelled using pip and reinstall all python packages using pacman or virtualenv. if you need python packages for arch you can search through AUR or you can install any python packages in a virtual environment.
If you want the most up-to-date version from pypi and not from repository, then do something like
pip install -U pip
Related
I had Python versions of 2.7 and 3.5. I wanted the install a newer version of Python which is python 3.8. I am using Ubuntu 16.04 and I can not just uninstall Python 3.5 due to the dependencies. So in order to run my scripts, I use python3.8 app.py. No problem so far. But when I want to install new packages via pip:
python3.8 -m pip install pylint
It throws an error:
AttributeError: module 'platform' has no attribute 'linux_distribution'
So far, I tried:
sudo update-alternatives --config python3
and chose python3.8 and run command by starting with python3 but no luck.
Then:
sudo ln -sf /usr/bin/python3.5 /usr/bin/python3
I also tried running the command by starting with python3 but it did not work either.
How can I fix it so that I can install new packages to my new version of Python?
It looks like at least on my Ubuntu 16.04, pip is shared for all Python versions in /usr/lib/python3/dist-packages/pip.
This is what I did to get it working again:
sudo apt remove python3-pip
sudo python3.8 -m easy_install pip
You might want to install the python 3.5 version of pip again with sudo python3.5 -m easy_install pip.
Python 3.8 removed some stuff. I solved my problems with pip (specifically pip install) by installing pip with curl.
What worked for me was downloading get-pip.py and run it with Python 3.8:
cd ~/Downloads
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.8 get-pip.py
Source: https://pip.pypa.io/en/stable/installing/
The problem is that package.linux_distribution was deprecated starting with Python 3.5(?). and removed altogether for Python 3.8.
Use the distro package instead. This package only works on Linux however.
I ran into this problem after installing OpenCobolIDE on Linux Mint 20, having upgraded Python to the latest level. have submitted a code fix to the OpenCobolIDE author to review and test. I was able to get the IDE to start up and run with this fix.
Essentially the fix uses the distro package if available, otherwise it uses the old platform package. For example:
This code imports distro if available:
import platform
using_distro = False
try:
import distro
using_distro = True
except ImportError:
pass
Then you can test the value of using_distro to determine whether to get the linux distro type from package or distro, for example:
if using_distro:
linux_distro = distro.like()
else:
linux_distro = platform.linux_distribution()[0]
In my case, removing python-pip-whl package helped:
apt-get remove python-pip-whl
It removed also pip and virtualenv, so I had to install them again:
curl https://bootstrap.pypa.io/get-pip.py | python3
pip install virtualenv
Check if your wheels installation is old. I was getting this same error and fixed it with
python3.8 -m pip install --upgrade pip setuptools wheel
Pylint seems to work on python3.8
I recently had this error and it turns out that I had a package called platform at a folder on my path ahead of the standard library and so the interpreter imported that instead. Check your path to what it is that you're actually importing.
If you have this issue when running a docker-compose up command. The solutions above do not work. You should install docker ce (https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04)
I am trying to run a webpage using python flask and connecting it with the database of MySQL and while installing MySQL packages I'm receiving this error.
I'm doing this on ec2 Linux AWS.
TL;DR
The 'ideal' solution (Ubuntu/Debian way):
$ python -m pip uninstall pip to uninstall the new pip 10 and retain your Ubuntu/Debian-provided patched pip 8. For a system-wide installation of modules use apt wherever possible (unless you are in a virtualenv), more on it below. In older Ubuntu/Debian versions, always add --user flag when using pip outside of virtualenvs (installs into ~/.local/, default in python-pip and python3-pip since 2016).
If you still want to use the new pip 10 exclusively, there are 3 quick workarounds:
simply re-open a new bash session (a new terminal tab, or type bash) - and pip 10 becomes available (see pip -V). debian's pip 8 remains installed but is broken; or
$ hash -d pip && pip -V to refresh pip pathname in the $PATH. debian's pip 8 remains installed but is broken; or
$ sudo apt remove python-pip && hash -d pip (for Python 3 it's python3-pip) -- to uninstall debian's pip 8 completely, in favor of your new pip 10.
Note: You will always need to add --user flag to non-debian-provided pip 10, unless you are in a virtualenv! Your use of pip 10 system-wide, outside of virtualenv, is not really supported by Ubuntu/Debian. Never sudo pip!
Details:
https://github.com/pypa/pip/issues/5221#issuecomment-382069604
https://github.com/pypa/pip/issues/5240#issuecomment-381673100
So, here we have Python 2.7.12 in Ubuntu 16.04 ec2 machine, and get ImportError: cannot import name main when trying to use pip. It's caused by the pip install --upgrade pip command: that installs the latest pip version 10 alongside Ubuntu's default pip version from python-pip debian package from OS distribution (the system Python installation), completely bypassing Ubuntu apt subsystem. It breaks the Ubuntu's default pip: the debian-patched launcher script from python-pip (system-installed to /usr/bin/pip*) tries to do import main() from your newly installed pip 10 library, but with a different import path, so it fails.
This error is discussed in more detail in a developer thread of the pip issue tracker, including a few proposed solutions, such as:
The $ hash -d pip command: when hash is invoked, the full pathname of pip is determined by searching the directories in $PATH and remembered. Any previously-remembered pathname is discarded. The -d option causes the shell to "forget" the remembered location of the given package name; or
Similarly, you can simply re-open a new bash session (a new terminal tab) to refresh pip pathname in $PATH; or
You could just use a versioned pip2 command (or pip3 for Python 3) instead of pip to invoke the older system-installed launcher /usr/bin/pip2 , whereas any pip script located in $HOME/.local/bin dir (pip, pip2, pip2.7) will invoke your new user-installed pip 10 version;
You can also use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip, for example:
$ python2 -m pip install --user SomePackage # default Python 2
$ python2.7 -m pip install --user SomePackage # specifically Python 2.7
That is handy if you have several versions of Python and need an extension from PyPI, such as your MySQL-python module (MySQLdb) or a Flask-MySQL, for a specific Python version. The --user switch is only required outside of virtualenv.
Or, uninstall one of the two pips – either user-installed or system-installed – to resolve the conflict:
$ python -m pip uninstall pip – to remove your manually-installed pip in favour of the previously installed Ubuntu-shipped version from python-pip debian package (python3-pip for Python 3); it is slightly older, but it finds and installs latest modules from PyPI just fine, and has a working pip command in the $PATH by default; or
$ sudo apt-get remove python-pip – to uninstall Ubuntu-provided pip in favour of your latest pip 10; if it is not accessible via the short pip command, just add your $HOME/.local/bin directory to your $PATH environment variable to use pip command (see above).
Note: Ubuntu 16.04 pip v8.1.1 and the latest pip v10.0.1 produce exactly the same PyPI index search results and can pull the same module versions;
Finally, you could ignore both pips altogether in favor of APT, and install Python packages system-wide from Ubuntu repo with:
$ apt search <python-package> # or apt-cache search in older Ubuntu
$ apt show <python-package> # e.g. python-flask
$ sudo apt install <python-package> # or sudo apt-get install
Packages prefixed with python- are for Python 2; with python3- are for Python 3.
Standard apt-get installation method may be what you need. For example, in your case:
python-mysqldb - Python interface to MySQL <- a fork of MySQLdb == MySQL-python
python-flask-sqlalchemy - SQL Alchemy support
python-pymysql - pure Python MySQL driver
In fact, python-packages from Ubuntu repository are preferred whenever possible, particularly in case of heavy system dependencies or when used system-wide.
Of course, the amount of Python packages in Ubuntu repository (few thousand!) is relatively smaller compared to PyPI (and have only one version of them), because any OS repository is lagging slightly behind PyPI versions. But the upside of APT is that all the Ubuntu-provided packages underwent integration testing within Ubuntu, plus apt-get quickly resolves heavy dependencies like C extensions automatically. You will always get the system libraries you need as part of the apt install, but with pip you have no such guarantees.
APT may not be an option, however, if you really need only the latest (or certain older) package version, or when it can only be found at PyPI, or when modules need to be isolated; then pip is indeed more appropriate tool. If you have to use pip install command on Ubuntu instead of apt-get install, please ensure it runs in an isolated virtual development environment, such as with virtualenv (sudo apt-get install python-virtualenv), or using a built-in venv module (available in python3 only), or at a per-user level (pip install --user command option), but not system-wide (never sudo pip!).
Note: Using sudo pip command (with root access) on Ubuntu/Debian should be avoided, because it interferes with the operation of the system package manager (apt) and may affect Ubuntu OS components when a system-used python module is unexpectedly upgraded, particularly by dependencies on another pip package. It is advised to never use Pip to change system-wide Python packages, as these are managed by apt-get on Ubuntu.
These steps worked for me.
1- Uninstall the pip update from python.
2- Uninstall pip package from your Ubuntu.
3- Check that pip binary is not longer in your system.
python -m pip uninstall pip
apt remove python-pip
whereis pip
4- Download and install pip. (credits for VanDragt.com)
wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py
sudo python3 /tmp/get-pip.py
pip install --user pipenv
pip3 install --user pipenv
echo "PATH=$HOME/.local/bin:$PATH" >> ~/.profile
source ~/.profile
whereis pip
Now you should be able to install any pip package you want.
My cent, I had the same ImportError: cannot import name main.
My system is a Linux Ubuntu distro, I have executed this command:
python -m pip uninstall pip
This has removed one local (for the user) pip version.
I had already an older pip/pip2 system executable (apt-get installed in ancient times) that worked like a charm.
As suggested in pip's github issue
The temporary fix is -
Edit your /usr/bin/pip file and comment the line importing main and edit it
#from pip import main
from pip._internal import main as main
Worked perfectly for me.
Note - this is a temporary fix. Wait for team pip to fix this.
OR
from pip import main
if __name__ == '__main__':
sys.exit(main())
to this:
from pip import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
As suggested in this SO answer.
Try this
Check the python version you use
# Python --version
and try installing for eg if your version is 2.7
#python2.7 <package name>
Will work fine......
I have faced the similar issue after pip 19 upgrade. So I did the following to fix the problem.
pip install --upgrade pip==9.0.3
instead of
pip install -U pip
I've tried to install psycopg2 (PostgreSQL Database adapater) from this site, but when I try to install after I cd into the package and write
python setup.py install
I get the following error:
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've also tried 'sudo pip install psycopg2' and I got the same message.
After reading through the docs, it asks to look at the setup.cfg file (which is below):
[build_ext]
define=
# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4
# PSYCOPG_DEBUG can be added to enable verbose debug information
# "pg_config" is required to locate PostgreSQL headers and libraries needed to
# build psycopg2. If pg_config is not in the path or is installed under a
# different name uncomment the following option and set it to the pg_config
# full path.
#pg_config=
# Set to 1 to use Python datetime objects for default date/time representation.
use_pydatetime=1
# If the build system does not find the mx.DateTime headers, try
# uncommenting the following line and setting its value to the right path.
#mx_include_dir=
# For Windows only:
# Set to 1 if the PostgreSQL library was built with OpenSSL.
# Required to link in OpenSSL libraries and dependencies.
have_ssl=0
# Statically link against the postgresql client library.
#static_libpq=1
# Add here eventual extra libraries required to link the module.
#libraries=
However, I'm not sure if I'm suppose to edit this file, since the documentation states the following:
then take a look at the setup.cfg file.
Some of the options available in setup.cfg are also available as command line arguments of the build_ext sub-command. For instance you can specify an alternate pg_config version using:
$ python setup.py build_ext --pg-config /path/to/pg_config build
Use python setup.py build_ext --help to get a list of the options supported.
I've gotten the list of options supported but I'm not sure where to go from there
Debian/Ubuntu
Python 2
sudo apt install libpq-dev python-dev
Python 3
sudo apt install libpq-dev python3-dev
Additional
If none of the above solve your issue, try
sudo apt install build-essential
or
sudo apt install postgresql-server-dev-all
With pip
Install the psycopg2-binary PyPI package instead, it has Python wheels for Linux and Mac OS.
pip install psycopg2-binary
I was getting this issue because I hadn't yet installed PostgreSQL on my machine.
For Mac
brew install postgresql
For Mac without brew
python3 -m pip install psycopg2-binary
If you need to install without compiling:
pip install psycopg2-binary
https://www.psycopg.org/docs/install.html#binary-install-from-pypi
Note: The psycopg2-binary package is meant for beginners to start
playing with Python and PostgreSQL without the need to meet the build
requirements. If you are the maintainer of a publish package depending
on psycopg2 you shouldn’t use ‘psycopg2-binary’ as a module
dependency. For production use you are advised to use the source distribution.
If you are on Ubuntu or any other debian-based distro, try
sudo apt-get install python3-psycopg2
Otherwise, you need to find and install the Postgresql client packages for your distribution. psycopg2 installation from source
On Macbook with M1 i had to install postgresql
brew install postgresql
(If you don't have brew: https://brew.sh)
then run the install again
python3 -m pip install psycopg2-binary
Upgrading pip worked for me: pip install --upgrade pip
For OSX with Macports, you can install sudo port install py38-psycopg2 for Python 3.8. You can search for your version of Python with port search psycopg2. At the time of writing, the versions range from 2.7 to 3.9 all up to date with version 2.8.6 of psycopg2.
Note: This probably will not help in a venv.
Edit: So to find your pg_config for a venv, run the command port contents postgresql13 | grep pg_config where postgresql13 is the version of the package of postgresql installed from the above port command. You are looking for a path such as /opt/local/lib/postgresql13/bin/pg_config. Export that to your PATH variable with a command such as export PATH=/opt/local/lib/postgresql13/bin/:$PATH.
Refer to this answer for Homebrew.
On Fedora (tested and built from source on Fedora 35)
pg_config is present in libpq5-devel.
Now try these steps:
sudo dnf install libpq5-devel
python setup.py build
sudo python setup.py install
If you installed Postgres.app on macOS, add its bin directory to the PATH environment variable:
export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
For mac os
install postgresql with : brew install postgresql
then
install psycopg2 with : pip install psycopg2
worked for me
Incase you are using PyCharm/Visual Code Studio terminal, don't do it. Use the default system terminal, as it ensures correct format of brew install is done.
On M1 pro with Intel chip:
brew install postgresql
pip install psycopg2
For me just this worked on Mac:
pip install --upgrade pip
pip install psycopg2-binary
For Mac
I had this issue too. I had followed a guide that had me run
brew install postgresql#15
This worked, but I kept getting the error
Error: pg_config executable not found.
So I then tried to brew install postgres without the #15 after it, and it worked! So, if you have installed postgresql#15 or #any-number, try to brew install without a number.
brew install postgresql
Your error is becouse didn't install the prerequisites on your machine or environment.
You can install prerequisites from here.
In this case probably your missing prerequisite is postgresql you can try below instructors.
For Mac
brew install postgresql
For Linux
sudo apt-get install postgresql
For people building postgres and psycopg2 from source like me, another solution is here:
sudo su
export PATH=/usr/local/pgsql/bin:$PATH #or path to your pg_config
Now setup.py from psycopg2 could find pg_config correctly.
python3 setup.py install
or if you just want to use pip3, pip3 install psycopg2 should work too.
I am trying to run Google's deep dream. For some odd reason I keep getting
ImportError: No module named google.protobuf
after trying to import protobuf. I have installed protobuf using sudo install protobuf. I am running python 2.7 OSX Yosemite 10.10.3.
I think it may be a deployment location issue but i cant find anything on the web about it. Currently deploying to /usr/local/lib/python2.7/site-packages.
There is another possibility, if you are running a python 2.7.11 or other similar versions,
sudo pip install protobuf
is ok.
But if you are in a anaconda environment, you should use
conda install protobuf
Locating the google directory in the site-packages directory (for the proper latter directory, of course) and manually creating an (empty) __init__.py resolved this issue for me.
(Note that within this directory is the protobuf directory but my installation of Python 2.7 did not accept the new-style packages so the __init__.py was required, even if empty, to identify the folder as a package folder.)
...In case this helps anyone in the future.
In my case I
downloaded the source code, compiled and installed:
$ ./configure
$ make
$ make check
$ sudo make install`
for python I located its folder(python) under source code, and ran commands:
$ python setup.py build
$ python setup.py install'
Not sure if this could help you..
I got the same error message when I tried to use Tensor Flow. The solution was simply to uninstall Tensor Flow and protobuf:
$ sudo pip uninstall protobuf
$ sudo pip uninstall tensorflow
And reinstall it again: pip installation of Tensorflow. Currently, this is:
# Ubuntu/Linux 64-bit, CPU only:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
# Mac OS X, CPU only:
$ sudo easy_install --upgrade six
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0rc0-py2-none-any.whl
when I command pip install protobuf, I get the error:
Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
If you have the same problem as me, you should do the following commands.
pip install --ignore-installed six
sudo pip install protobuf
According to your comments, you have multiply versions of python
what could happend is that you install the package with pip of anthor python
pip is actually link to script that donwload and install your package.
two possible solutions:
go to $(PYTHONPATH)/Scripts and run pip from that folder that way you insure
you use the correct pip
create alias to pip which points to $(PYTHONPATH)/Scripts/pip and then run pip install
how will you know it worked?
Simple if the new pip is used the package will be install successfully, otherwise the package is already installed
I installed the protobuf with this command:
conda install -c anaconda protobuf=2.6.1
(you should check the version of protobuf)
In my case, MacOS has the permission control.
sudo -H pip3 install protobuf
I had this problem to when I had a google.py file in my project files.
It is quite easy to reproduce.
main.py: import tensorflow as tf
google.py: print("Protobuf error due to google.py")
Not sure if this is a bug and where to report it.
Im trying to install python through brew with:
brew install python
But get the following error:
Stevens-MacBook-Pro :: ~ ‹master*› » brew install python
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/python-2.7.
Already downloaded: /Library/Caches/Homebrew/python-2.7.8_2.mountain_lion.bottle.tar.gz
==> Pouring python-2.7.8_2.mountain_lion.bottle.tar.gz
==> Caveats
Setuptools and Pip have been installed. To update them
pip install --upgrade setuptools
pip install --upgrade pip
You can install Python packages with
pip install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: https://github.com/Homebrew/homebrew/wiki/Homebrew-and-Python
.app bundles were installed.
Run `brew linkapps` to symlink these to /Applications.
/usr/bin/install_name_tool: object: /usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python malformed object (unknown load command 10)
Error: Failed to fix install names
The formula built, but you may encounter issues using it or linking other
formula against it.
==> /usr/local/Cellar/python/2.7.8_2/bin/python -ssetup.py --no-user-cfg instal
using one of the approaches described here:
Please make the appropriate changes for your system and try again.
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall python`
==> Summary
🍺 /usr/local/Cellar/python/2.7.8_2: 4626 files, 73M
The error messages says the post install fails, and to try installing it again with:
brew postinstall python
but the error still persists. I also tried brew linkapps and it success fully links python but when I run pip from the console I get this error:
Stevens-MacBook-Pro :: ~ ‹master*› » pip
zsh: /usr/local/bin/pip: bad interpreter: ##HOMEBREW_PREFIX##/opt/python/bin/python2.7: no such file or directory
Any idea what might be going wrong?
Pyenv is a python version management tool, something like rbenv but for python.
You could easily install and change python version via pyenv easily.
The following shows how to install python with version 2.7.8 through pyenv:
ubuntu#ubuntu:~$ pyenv install 2.7.8
Downloading Python-2.7.8.tgz...
-> http://yyuu.github.io/pythons/74d70b914da4487aa1d97222b29e9554d042f825f26cb2b93abd20fdda56b557
Installing Python-2.7.8...
Installing setuptools from https://bootstrap.pypa.io/ez_setup.py...
Installing pip from https://bootstrap.pypa.io/get-pip.py...
Installed Python-2.7.8 to /home/ubuntu/.pyenv/versions/2.7.8
as you can see, its very simple.
The command pyenv install "version" help you to install a specific versions of python easily and even pip, setuptools are also automatically installed.
I suggest giving pyenv a try!!