Install pip failed - python

i am using redhat 5.3
I using following command to update python to 2.7. (it was python 2.4 before update)
# xz -d Python-2.7.6.tar.xz
# tar xvf Python-2.7.6.tar
# cd Python-2.7.6/
# ./configure
# make && make install
And I Install the python-setuptools
# yum install python-setuptools
Then I install the pip print the error
^
SyntaxError: invalid syntax
File "/usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg/pip/_vendor/colorama/__init__.py", line 2
from .initialise import init, deinit, reinit
^
SyntaxError: invalid syntax
File "/usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg/pip/_vendor/colorama/winterm.py", line 2
from . import win32
^
SyntaxError: invalid syntax
Adding pip 1.5.6 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip2 script to /usr/bin
Installing pip2.4 script to /usr/bin
Installed /usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg
Processing dependencies for pip
And I run the command pip , it print following errors:
# pip
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2603, in <module>
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 666, in require
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: pip==1.5.6
And I try to uninstall that, it tell me that:
[root#linkea-dev-srv1 /]# yum remove pip
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Setting up Remove Process
No Match for argument: pip
Loading mirror speeds from cached hostfile
No Packages marked for removal
You have new mail in /var/spool/mail/root
So I try to reinstall pip by python get-pip.py.
It also has error.
# python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 17474, in <module>
main()
File "get-pip.py", line 17466, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 17406, in bootstrap
import pip
File "/tmp/tmpB9jhvw/pip.zip/pip/__init__.py", line 9, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/log.py", line 9, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/__init__.py", line 2, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/initialise.py", line 5, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/ansitowin32.py", line 6, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/winterm.py", line 2, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/win32.py", line 7, in <module>
File "/usr/local/lib/python2.7/ctypes/__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes

You should be very careful when upgrading Python on RedHat (including Fedora/CentOS) because a large majority of the system applications rely on the bundled version of Python. This is especially true of yum, which relies on the version of Python that comes bundled with the operating system.
In short - if you upgrade the version of Python on RedHat/CentOS/Fedora, yum will not work correctly.
To install a different version of Python on these distributions, you have two main options. One is to find someone that has released a rpm, download an install that; but you may have to deal with dependencies on your own.
The other (simpler) option is to download the source of Python, compile it and then install it separately (using altinstall).
You'll need to install the following packages first:
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel
Next, download the source and extract it. As of this writing, the latest version is 2.7.8:
wget "https://www.python.org/ftp/python/2.7.8/Python-2.7.8.xz"
tar xvf Python-2.7.8.xz
cd Python-2.7.8
Now you have to build and install Python to an alternate location, with the following:
./configure --prefix=/usr/local
make && make altinstall
Once this is done, you'll have /usr/local/bin/python2.7 available to you. Next, you'll want to install pip for this version of Python. To do that, first install setuptools:
wget "https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py"
/usr/local/bin/python2.7 ez_setup.py
/usr/local/bin/easy_install-2.7 pip
The final step is to make sure that this version of Python is available to you. You can add /usr/local/bin/ to your $PATH by modifying your shell's environment (for example, adding it in $HOME/.bashrc); or you can as root create symbolic links in /usr/bin/ to these utilities. Make sure you give them version-specific tags:
ln -sf /usr/local/bin/python2.7 /usr/bin/python2.7
ln -sf /usr/local/bin/pip /usr/local/bin/pip2.7
This will keep your default Python to the system's version (recommended), and then give you the option to use 2.7 when needed.

Related

ModuleNotFoundError: No module named 'dnf' when running yum or dnf

A few days ago I wanted to run dnf but I received the following error
Traceback (most recent call last):
File "/usr/bin/dnf", line 57, in <module>
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
Thus I tried to run yum and I received something similar:
Traceback (most recent call last):
File "/usr/bin/yum", line 57, in <module>
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
I do not know what happened and I hope someone can help me find the problem and solve it. The only thing I know is that it might be related to the fact that a few days before I installed tensorflow in python using conda. Although it seems conda does not work now because I get this:
Traceback (most recent call last):
File "/usr/bin/conda", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
#_call_aside
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 581, in _build_master
ws.require(__requires__)
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 898, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 784, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'conda==4.5.11' distribution was not found and is required by the application
I am using fedora 29
Thanks!
I had the same problem, but after all trial and error the only thing actually worked was:
rpm -qa python3
This will announce your python3 rpm package.
I've searched and downloaded it from web
Go to the downloaded directory like:
sudo rpm -e --nodeps python3-3.7.2-4.fc29.x86_64(my python3 rpm package)
sudo rpm -i python3-3.7.2-4.fc29.x86_64.rpm
I tried many other methods so this'll not be a only factor that resolve that problem.
Hello,
i have just been through this in Fedora 31 and do not exactly know what was the cause that led to this same issue, it must have been some package managing over another context that came up only on my next need to use DNF.
I am assuming that before this stated error:
Traceback (most recent call last):
File "/usr/bin/dnf", line 57, in
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
You were having this message when executing dnf:
/usr/local/lib/python3.7/site-packages/dnf.py:15: UserWarning: The DNF Python API is not currently available via PyPI.
Please install it with your distro package manager (typically called
'python2-dnf' or 'python3-dnf'), and ensure that any virtual environments
needing the API are configured to be able to see the system site packages
directory.
After some hours researching and trying to install each DNF rpm dependency of the DNF rpm itself(https://pkgs.org/download/dnf) i felt as an intuition that maybe i should try to remove(mv sure)
/usr/local/lib/python3.7/
which had just one folder in it named site-packages
It worked!
Thank you.
I have a friend who met the same problem.
He tried to uninstall python3.7 in linux server by some amazing cmd rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps and whereis python3 |xargs rm -frv.
This caused the yum and dnf to break.
I changed the /usr/bin/yum to use a local python3.8 version, but it caused ModuleNotFoundError: No module named 'dnf' at last, and didn't solved it.
It is not a good way to download many rpm packages on the Internet. And I can't use yum either. But I have another same linux OS server, so I've tried to copy the correlation files about python3.7.
$ rpm -ql python3-3.7.0-9.h4.eulerosv2r8.aarch64> py.log
$ while read -r line;do dirname $line |xargs -I {} ssh root#$remoteip "mkdir -p {}" ;scp $line root#$remoteip:$line ;done<py.log
$ rpm -ql python3-libs-3.7.0-9.h4.eulerosv2r8.aarch64 >pylib.log
$ while read -r line;do dirname $line |xargs -I {} ssh root#$remoteip "mkdir -p {}" ;scp $line root#$remoteip:$line ;done<pylib.log
scp -r /usr/lib/python3.7/site-packages root#$remoteip:/usr/lib/python3.7/
I recovered yum this way.
I had the same issue.
For me the solution was to simply uninstall the python3 dnf package (including from all virtualenvs) that I had obviously installed somewhen.
pip uninstall dnf
had the same error.
my fix ->
cd into /usr/bin. has many python files...
latest python (3.11) has pytest, python3 -> python3.11 (symlink), python3.11, python3.11-config, python3.11-x86_64-config, python -> python3
had been using 3.9, not familiar with python so much, so changed symlink back to python3->python3.9 after Fedora 36 update changed symlink to 3.11 and installed python3.11. when i changed symlink back to 3.9, this created the error message. When i changed the symlink back to python3->python3.11 the error disappeared and all works fine. DNF is fine etc. did nothing else.
since all the other python files were pointing to the 3.11 versions, introduction of the symlink to 3.9 must have blown the fuse...

Pydoop Installation on CentOS 6

I am trying to install Pydoop (https://crs4.github.io/pydoop/installation.html) on CentOS 6 (Hortonworks HDP physical cluster, 4 nodes). I have Python 3.4 and Python 2.6 installed on my master. When I install it using Python 3 it shows syntax error like below:
[root#abc]# python3 setup.py build
File "setup.py", line 45
print 'using setuptools version', setuptools.__version__
^
SyntaxError: Missing parentheses in call to 'print'
When I install it using Python 2 it shows following error
[root#abc]# python setup.py build
using setuptools version 35.0.2
Traceback (most recent call last):
File "setup.py", line 65, in <module>
import pydoop
File "/root/pydoop/pydoop/__init__.py", line 42, in <module>
_HADOOP_INFO = _PATH_FINDER.find() # fill the cache ASAP
File "/root/pydoop/pydoop/hadoop_utils.py", line 624, in find
info[a] = getattr(self, a)()
File "/root/pydoop/pydoop/hadoop_utils.py", line 433, in hadoop_home
_hadoop_home_from_version_cmd() or
File "/root/pydoop/pydoop/hadoop_utils.py", line 394, in
_hadoop_home_from_version_cmd
output = sp.check_output([hadoop_exec, 'version'])
AttributeError: 'module' object has no attribute 'check_output'
I don't want to upgrade default python from 2.6 to 2.7 as it may break yum which uses python2.6 and upgrading it may cause problems. Any suggestions please?
You can install Python 2.7 and pip on CentOS 6 without breaking yum:
# yum update
# yum install centos-release-SCL epel-release
# yum install python27 python27-devel
# echo ". /opt/rh/python27/enable" >/etc/profile.d/python.sh
# source /etc/profile
# curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py
# python get-pip.py
# python --version
Python 2.7.13
# pip --version
pip 9.0.1 from /opt/rh/python27/root/usr/lib/python2.7/site-packages (python 2.7)

Python DistributionNotFound Error after installing EB CLI 3.0

Have tried many things, but keep getting this error after multiple attempts to update python, pip, etc. I am on OS X running 10.9.5.
CMD% eb
Traceback (most recent call last):
File "/usr/local/bin/eb", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: python-dateutil>=2.1,<3.0.0
I was experiencing a similar error when trying to run eb, though not for dateutil...
Traceback (most recent call last):
File "/usr/local/bin/eb", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: requests>=2.6.1,<2.7
For me the solution was to update setuptools:
sudo pip install --upgrade setuptools
Hope that helps somebody.
Use the following command:
pip install awsebcli
It will automatically upgrade all dependecies of awsebcli.
use the following command
sudo pip install python-dateutil
to upgrade it
Pip is probably linked to a different version of python then standard.
You should try installing pip using
python get-pip.py
(You can download get-pip.py from the pip website)
Otherwise, You can see which Python everything is linked too.
which python
head -1 $(which eb)
head -1 $(which pip)
You can change to shebang line in the eb script to match pip and it should all work.
You can also install using a virtualenv (pythons recommended way of installing)
virtualenv ~/ebenv
source ~/ebenv/bin/activate
pip install awsebcli
deactivate
sudo ln -s ~/ebenv/bin/eb /usr/local/bin/
in my case on mac osx 10.10, I had to reinstall.
sudo pip install python-dateutil
Just in case some runs into this type of error. check the last paragraph in the trace for the kind of error that it is being raised. In my case, this was:
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (six 1.4.1
(/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
Requirement.parse('six>=1.5'), set(['python-dateutil']))
I had the exact same issue, for me, the eb script was using the wrong python. To solve it I just modified the eb script:
> which eb
/usr/local/bin/eb
> sudo vim /usr/local/bin/eb
## Change the first line from '#!/usr/bin/python' to '#!/usr/local/bin/python'
After restarting the terminal, everything work as expected.
From the raised error in your log, it needs python-dateutil>=2.1.
So you need to make sure that version is installed and install it if not. I had similar issue, and the solution (in my case) is:
$ pip install --ignore-installed python-dateutil==2.2

hdf5 / h5py ImportError: libhdf5.so.7

I'm working on a project involving network messaging queues (msgpack, zmq, ...) on a RHEL 6.3 (x86_64) system. I was installing the most recent packages of glib, gevent, pygobject, pygtk, and such in order to get pylab / matplotlib to work (which hasn't been successful either).
After giving up I went back to my code and somehow I had managed to wreck my hdf5 / h5py installation - h5py can't find libhdf5.so.7 on import. I immediately reinstalled hdf5-1.8.9 in /usr/local/hdf5 on RHEL 6.3 (x86_64) as follows:
./configure --prefix=/usr/local/hdf5
make
make check
sudo make install
make check install
which seemed to work just fine. Then I went to reinstall h5py (in python 2.7.3):
python2.7 setup.py build --hdf5=/usr/local/hdf5/
python2.7 setup.py test # optional
# sudo python2.7 setup.py install
which fails to import the _errors file in the tests, like so:
======================================================================
ERROR: _hl.tests.test_attrs_data (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: _hl.tests.test_attrs_data
Traceback (most recent call last):
File "/usr/local/lib/python2.7/unittest/loader.py", line 252, in _find_tests
module = self._get_module_from_name(name)
File "/usr/local/lib/python2.7/unittest/loader.py", line 230, in _get_module_from_name
__import__(name)
File "/home/cronburg/Downloads/h5py-2.0.1/build/lib.linux-x86_64-2.7/h5py/_hl/tests/test_attrs_data.py", line 5, in <module>
import h5py
File "/home/cronburg/Downloads/h5py-2.0.1/build/lib.linux-x86_64-2.7/h5py/__init__.py", line 1, in <module>
from h5py import _errors
ImportError: libhdf5.so.7: cannot open shared object file: No such file or directory
----------------------------------------------------------------------
Ran 12 tests in 0.001s
FAILED (errors=12)
h5py was working fine before I went to install the aforementioned packages / tarballs, and I don't remember touching anything that even remotely looked like hdf5. Any ideas?
EDIT:
Trying to locate the file only shows it in the location i untarred it:
cronburg#rhel:~/Downloads/h5py-2.0.1$ locate libhdf5.so.7
/home/cronburg/tmp/hdf5-1.8.9/hdf5/lib/libhdf5.so.7
/home/cronburg/tmp/hdf5-1.8.9/hdf5/lib/libhdf5.so.7.0.3
/home/cronburg/tmp/hdf5-1.8.9/src/.libs/libhdf5.so.7
/home/cronburg/tmp/hdf5-1.8.9/src/.libs/libhdf5.so.7.0.3
take a look on:
http://rpm.pbone.net/index.php3/stat/3/srodzaj/1/search/libhdf5.so.7()(64bit)
Or should try this repo: https://ius.io/Packages/
I prefer always use the most updated python version, in a package format.
https://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/repoview/python27.html
sudo yum install -y https://centos6.iuscommunity.org/ius-release.rpm
sudo yum install -y python27
sudo yum install -y python27-devel
Do a pip install and be happy:
$ sudo pip install h5py
Installing collected packages: h5py
Successfully installed h5py-2.6.0
This also happened to me when using h5py on a clean raspbian. You need to install the system libraries first.
apt install libhdf5-dev
then
pip install h5py

Easy_install and Pip doesn't work

Easy_install and Pip doesn't work anymore on python 2.7, when I try to do:
sudo easy_install pip
I get:
Traceback (most recent call last):
File "/usr/bin/easy_install", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/bin/lib/python2.7/site-packages/distribute-0.6.19-py2.7.egg/pkg_resources.py", line 2713, in <module>
parse_requirements(__requires__), Environment()
File "/usr/bin/lib/python2.7/site-packages/distribute-0.6.19-py2.7.egg/pkg_resources.py", line 584, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: distribute==0.6.15
And when I try:
sudo pip install [package]
I get:
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/bin/lib/python2.7/site-packages/distribute-0.6.19-py2.7.egg/pkg_resources.py", line 2713, in <module>
parse_requirements(__requires__), Environment()
File "/usr/bin/lib/python2.7/site-packages/distribute-0.6.19-py2.7.egg/pkg_resources.py", line 584, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==0.8.2
I've already install both of them (and yes, first deleted them), but no result...
Thanks!
(I tried already this post)
I had this issue where python's distribute package wasn't installed for some reason. After following the instructions on python-distribute, i got it working.
install the distribute package as follows:
$ wget https://web.archive.org/web/20100225231201/http://python-distribute.org/distribute_setup.py
$ python distribute_setup.py
EDIT: http://python-distribute.org/distribute_setup.py no longer works:
hopefully this will resolve your problem with running
$ sudo easy_install
Happy Coding!
If you installed a new version of easy_install through Distribute, the new command may have been installed in another directory, most likely /usr/local/bin/. But the traceback shows you were using /usr/bin/easy_install. Try this:
sudo /usr/local/bin/easy_install ...
Try
sudo easy_install Distribute
and if that exists, but is too old
sudo easy_install -U Distribute
Looks like either Distribute/setuptools (it's old name) is messed up or Python package settings. If either of these do not help, try removing the full Python 2.7 installation and reinstall everything from the scratch.
Possible reasons for the mess is that you have used both sudo easy_install / sudo pip and Linux distribution packages to mix and match system-wide installation packages. You should use virtualenv instead if you use pip/easy_install (no sudo needed)
http://pypi.python.org/pypi/virtualenv
I had a similar problem, but things were working fine as root. In my case, I found that the permissions on the python packages were not readable by the ID I was running the command under.
To correct it, I ran the following command to open the permission for read and execute to all users:
sudo chmod o+rx -R /usr/local/lib/python2.7/dist-packages/*.egg
I had similar issue when trying to install package via pip with python 3.6 on windows. (pip is supposed to work out of the box with this install)
The problem was not running as administrator.
Running cmd as administrator and then installing my package worked:
python -m pip install pylint
I was trying to get pip to work on the 2.7.0 version, but it seems like it doesn't come with the easy_install/pip files (Script folder in main directory), installing 2.7.13 solved the problem for me.

Categories