I'm running VPS with ubuntu:
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
I tried to upgrade Python to 2.7.16 from 2.7.6.
Just after upgrade Gunicorn library failed to start with
Traceback (most recent call last):
File "/home/user/bin/python-2.7/bin/gunicorn", line 7, in <module>
from gunicorn.app.wsgiapp import run
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 9, in <module>
from gunicorn.app.base import Application
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/app/base.py", line 12, in <module>
from gunicorn import util
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/util.py", line 12, in <module>
import pkg_resources
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 82, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/pkg_resources/extern/__init__.py", line 61, in load_module
"distribution.".format(**locals())
ImportError: The 'packaging.requirements' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
I was told that it could be some setuptools issue, so I renewed them with
python -m ensurepip
Looking in links: /tmp/tmp98U8zf
Requirement already satisfied: setuptools in ./bin/python-2.7/lib/python2.7/site-packages (41.1.0)
Requirement already satisfied: pip in ./bin/python-2.7/lib/python2.7/site-packages (19.2.2)
(no changes)
I tried to do
pip install packaging
(no changes)
or downgrade setuptools to 19.2 (as suggested in Python 2.7 The 'packaging' package is required; normally this is bundled with this package)
and got
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/config.py", line 8, in <module>
import copy
File "/home/user/bin/python-2.7/lib/python2.7/copy.py", line 52, in <module>
import weakref
File "/home/user/bin/python-2.7/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
Is there any working way to upgrade to 2.7.16 python in my case?
UPD:
I upgraded python with it with
wget https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tgz
make clean && ./configure --enable-unicode=ucs4 --enable-shared --prefix=/home/user/bin/python-2.7/ --with-ensurepip=install && make && make install
pip install -r ~/django/django_projects/requirements.txt
pip freeze: https://www.pastiebin.com/5d592ea701503
Thanks.
Scenario
First: When trying to execute a Python script, the following error message appears:
ImportError: The 'packaging.requirements' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
Second: When trying to check the version of setuptools with pip show setuptools (or when using any other pip command), the next error message appears:
ImportError: cannot import name _remove_dead_weakref
Reason
This is because the current Python installation is somehow screwed up. In my case the mess was caused by an upgrade from Ubuntu 16.04 to Ubuntu 18.04.
Solution
With Virtual Environment
In the best case you were already using a virtual environment (this was my case). The solution here would be to recreate/setup your venv again (step-by-step):
$ cd /path/to/your/venv
# remove your old venv
$ rm -rf ./*
# create a new one
$ /usr/bin/virtualenv . --python=YOUR-PYTHON-VERSION
# activate venv
$ source bin/activate
# verify the correct python version is installed
$ python --version
For example replace YOUR-PYTHON-VERSION with python2.7 or python3.7.
After recreating your venv the problem should be fixed and you should be able to use pip again.
Without Virtual Environment
I think the best way to fix the problem would be to completely uninstall all non-default Python versions (for example Ubuntu 18.04 comes with Python 3.6+) and then make a clean reinstall of all other Python versions needed.
Try upgrading pip by typing:
pip install --upgrade pip
Related
I recently had tried to run a pip command and noticed my pip version was considerably out of date so upgraded it. This seems to have completely broken my pip install and I cannot figure out how to reset it.
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
You are using pip version 8.1.1, however version 22.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip3 install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/f3/77/23152f90de45957b59591c34dcb39b78194eb67d088d4f8799e9aa9726c4/pip-22.1-py3-none-any.whl (2.1MB)
100% |████████████████████████████████| 2.2MB 505kB/s
Installing collected packages: pip
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 22.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 11, in <module>
sys.exit(main())
File "/home/myname/.local/lib/python3.5/site-packages/pip/__init__.py", line 11, in main
from pip._internal.utils.entrypoints import _wrapper
File "/home/myname/.local/lib/python3.5/site-packages/pip/_internal/utils/entrypoints.py", line 12
f"pip{sys.version_info.major}",
^
SyntaxError: invalid syntax
This seems to come from this: https://github.com/pypa/pip/issues/9526
I can't seem to uninstall pip:
$ python3 -m pip uninstall pip
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/myname/.local/lib/python3.5/site-packages/pip/__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "/home/myname/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 57
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
I'm on python3.5 and can't seem to upgrade that either:
$ sudo apt-get install python3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
E: Couldn't find any package by regex 'python3.6'
I'm found a number of stackoverflow answers suggesting to use alternative repositories but they're not working either.
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
E: Couldn't find any package by regex 'python3.6'
I've tried 3.6, 3.7, 3.8, 3.9 and 3.10 with the same results.
I've also found some stack overflow answers suggesting to edit /usr/bin/pip3
Originally it looks like this:
from pip import main
if __name__ == '__main__':
sys.exit(main())
I've tried this:
from pip._internal import __main__
if __name__ == '__main__':
sys.exit(main())
and this:
I've tried this:
from pip._internal import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
But neither have resolved the issue.
To be sure i'm not messed up with a local version i've tried all of the above using /usr/bin/pip3 --version rather than just pip3 --version with the same results.
Now i'm at a bit of a loss how to get a working version of Python and Pip.
Suggestion from question:
$ sudo python3.5 -m easy_install pip
Searching for pip
Best match: pip 22.1
Adding pip 22.1 to easy-install.pth file
Installing pip3 script to /usr/local/bin
Installing pip3.10 script to /usr/local/bin
Installing pip script to /usr/local/bin
Using /home/myname/.local/lib/python3.5/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
$ ls -lh /usr/local/bin/*pip*
-rwxr-xr-x 1 root root 361 May 12 19:49 /usr/local/bin/pip
-rwxr-xr-x 1 root root 363 May 12 19:49 /usr/local/bin/pip3
-rwxr-xr-x 1 root root 369 May 12 19:49 /usr/local/bin/pip3.10
All 3 return the same thing:
$ /usr/local/bin/pip --version
$ /usr/local/bin/pip3 --version
$ /usr/local/bin/pip3.10 --version
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==22.1', 'console_scripts', 'pip')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2291, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2297, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/home/myname/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 57
sys.stderr.write(f"ERROR: {exc}")
^
I've now installed Python3.6 using "method two" from here: https://askubuntu.com/questions/1152640/apt-install-doesnt-install-python3-6 i.e. manual install
I've then upgraded pip using:
sudo python3.6 -m pip install pip --upgrade
Now pip --version and pip3 --version return an error but directly accessing the bin works:
$ /usr/local/bin/pip --version
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
The aliases are currently pointing to:
$ which pip
/home/sortitoutsi/.local/bin/pip
$ which pip3
/home/sortitoutsi/.local/bin/pip3
It seems that other things are now broken, such as aws.
$ aws --help
Traceback (most recent call last):
File "/usr/local/bin/aws", line 19, in <module>
import awscli.clidriver
File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 17, in <module>
import botocore.session
File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 29, in <module>
import botocore.configloader
File "/usr/local/lib/python2.7/dist-packages/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/usr/local/lib/python2.7/dist-packages/botocore/compat.py", line 26, in <module>
from dateutil.tz import tzlocal
File "/usr/local/lib/python2.7/dist-packages/dateutil/tz/__init__.py", line 1, in <module>
from .tz import *
File "/usr/local/lib/python2.7/dist-packages/dateutil/tz/tz.py", line 16, in <module>
from six import string_types, PY3
ImportError: No module named six
Simply reinstalling aws sudo python -m pip install awscli seemed to have fixed the above. I'm guessing a sudo apt-get update at some point forced an upgrade of awscli after finding an updated Python installation.
Do not try and install Python versions and packages (from another ppa) that are not supported by your OS. Your system may break.
Your attempted Pip installation is, luckily, in a local directory: $HOME/.local/. Check if there is anything else installed in $HOME/.local/bin/ and $HOME/.local/lib/python3.5/site-packages/. If nothing (or nothing that seems important), rename that directory:
mv ~/.local ~/.local_aside
Now, you should have the system Pip back again.
You may lose some other packages that you installed earlier (which would now be in ~/.local_aside, but possibly, you can reinstall those. Either with a system packages (e.g., python3-numpy), or again with pip3 install numpy and the like. Though pip may have trouble finding a correct NumPy version, since Python 3.5 is not supported anymore (the system package should be fine).
If you want to use a more recent version of Python, install a local (user-only) one. My preferred way of doing that is to use pyenv, which requires some set up (installing the necessary build packages). If you use pyenv, carefully read the installation instructions for your case. Once you get it going, you can quickly install any version of Python, and between minor versions, they won't even get in the way (that is, python3.9 -m pip install numpy will be a separate installation from python3.10 -m pip install numpy, and both can happily live next to each other if so wanted).
But don't use sudo and install it as a root: your system will get confused and may break.
Another alternative is Conda, in the form (my preference) of miniconda3. Conda can and will also install C library dependencies, and actively tries to resolve version conflicts between Python packages (in case you have to install a lot of packages). Again, browse the manual to get going, but it's relatively straightforward to use, and doesn't get in the way of your OS.
I'm new to Linux and I'm trying to install packages through a Makefile so users can run my Python 3 program.
sudo pip install python3-weather-api
However, even after uninstalling a previously installed version, the package seems to be going to the 2.7 version of Python.
Requirement already satisfied: python3-weather-api in /usr/local/lib/python2.7/dist-packages
Then, when I run the program, it can't find the module (it works locally in Python 3 just fine).
SystemExit: 1
Traceback (most recent call last):
File "project.py", line 11, in <module>
from weather import Weather
ImportError: No module named 'weather'
Is there a way I can point the original installation so when I run python3 project.py it can find the module?
Thanks very much!
I would recommend you to use pyenv to manage your Python installations, but, for now, try to run:
sudo pip3 install python3-weather-api
I'm getting this error when I try to install pip2.7.
I have python 2.7 as my default already, but I'm not sure why I'm getting this.
OS: CentOS 6.5
OpenSSL has been installed already.
I followed this guide to install Python 2.7:
http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
[root#myservername arandomfolder]# 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/tmpXq2wUP/pip.zip/pip/__init__.py", line 10, in <module>
File "/tmp/tmpXq2wUP/pip.zip/pip/util.py", line 18, in <module>
File "/tmp/tmpXq2wUP/pip.zip/pip/_vendor/distlib/version.py", line 14, in <module>
File "/tmp/tmpXq2wUP/pip.zip/pip/_vendor/distlib/compat.py", line 31, in <module>
ImportError: cannot import name HTTPSHandler
You have a Python without SSL support compiled. Unfortunately, get-pip appears to require SSL support.
If you are using a Linux distribution, make sure OpenSSL is installed, including the headers when compiling Python from source.
So looks like i was missing the openssl-devel dependency
after I had installed that, i was able to install this.
I was having this issue on a Centos 6.5 machine even though I had openssl and openssl-devel installed. I was also using the steps from the site:
http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
I removed python packages I had installed before: virtualenv, NetworkX, and pil:
pip uninstall virtualenv
pip uninstall NetworkX
pip uninstall pil
Then I compiled Python 2.7 again and no longer had this issue. After I followed the steps in the link below, I reinstalled the above packages using pip2.7:
pip2.7 install virtualenv
pip2.7 install NetworkX
pip2.7 install pil --allow-external pil --allow-unverified pil
I have meet the same problem. I solved it by install openssl-devel and reconfigure, make, make install python3:
yum install openssl-devel
then go to the python3 directory:
./configure --with-zlib --with-openssl
make
make install
I'm completely new to programming. I've been trying various ways to install NLTK on my Mac (running OS 10.5.8), and none of them is working. Please help! Here's what I've done so far.
Since at first I didn't realize that newer versions of Python required OS 10.6 or higher, I first tried to install the latest versions of both Python 3 and Python 2, but this obviously didn't work. I then cottoned on and found an older installation (the filename is python-2.7.6-macosx10.3.dmg), which installed successfully.
I then tried to follow the instructions on this page, which I copy below:
Install Setuptools: http://pypi.python.org/pypi/setuptools
Install Pip: run sudo easy_install pip
Install Numpy (optional): run sudo pip install -U numpy
Install PyYAML and NLTK: run sudo pip install -U pyyaml nltk
Test installation: run python then type import nltk
Steps 1 and 2 worked fine, but when I try steps 3 and 4, I get an error. The error is the same whether I try step 3 or step 4:
unknown0021E9E0E476:~ Tom$ sudo pip install -U numpy
Traceback (most recent call last):
File "/usr/local/bin/pip", line 8, in <module> load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 271, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 2173, in load_entry_point
return ep.load()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 1906, in loadentry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/Library/Python/2.5/site-packages/pip-1.4.1-py2.5.egg/pip/__init__.py", line 10, in <module>
from pip.util import get_installed_distributions, get_prog
File "/Library/Python/2.5/site-packages/pip-1.4.1-py2.5.egg/pip/util.py", line 17, in <module>
from pip.vendor.distlib import version
File "/Library/Python/2.5/site-packages/pip-1.4.1-py2.5.egg/pip/vendor/distlib/version.py", line 13, in <module>
from .compat import string_types
File "/Library/Python/2.5/site-packages/pip-1.4.1-py2.5.egg/pip/vendor/distlib/compat.py", line 276
return b''
^
SyntaxError: invalid syntax
I then found a different set of instructions on this page. It first has you install Xcode and MacPorts, which I did (again finding older versions compatible with 10.5.8). I got through the next few steps successfully: installed python27, made it the system default (sudo port select --set python python27), and installed the dependencies py27-numpy, py27-yaml, and py27-scipy. However, I can't install one needed package, py27-matplotlib. Here's what happens when I try:
unknown0021E9E0E476:~ Tom$ sudo port install py27-matplotlib
---> Computing dependencies for py27-matplotlib
---> Dependencies to be installed: py27-pyobjc-cocoa py27-pyobjc py27-six py27-tkinter tk Xft2 tcl xorg-libXScrnSaver xorg-scrnsaverproto py27-tornado py27-backports-ssl_match_hostname py27-backports
---> Staging py27-pyobjc into destroot
Error: org.macports.destroot for port py27-pyobjc returned: command execution failed
Error: Failed to install py27-pyobjc
Please see the log file for port py27-pyobjc for details:
/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_python_py-pyobjc/py27-pyobjc/main.log
Error: The following dependencies were not installed: py27-pyobjc-cocoa py27-pyobjc py27-six py27-tkinter tk Xft2 tcl xorg-libXScrnSaver xorg-scrnsaverproto py27-tornado py27-backports-ssl_match_hostname py27-backports
To report a bug, follow the instructions in the guide:
http://guide.macports.org/#project.tickets
Error: Processing of port py27-matplotlib failed
Without this package, I can't go on to install NLTK.
I've also tried installing NLTK in PyCharm, but that didn't work either: see this question. I'm at my wits' end here, so any help would be much appreciated!
ETA: Problem solved! I downloaded the tar.gz file from https://pypi.python.org/pypi/nltk and followed the install instructions in the package, and now I can import NLTK in the Python shell. Is it possible that I was simply trying to install things while in the wrong directory? (I'd still like to use NLTK in PyCharm, so answers to that question will still be welcome.)
Try installing the scipy package which includes matplotlib and numpy, I was a TA on a course where we used numpy and matplotlib quite a lot and using the scipy package to install was a solution for a lot of people.
The individual binary and source packages are available from: scipy docs
sudo port install py27-numpy py27-scipy py27-matplotlib py27-ipython +notebook py27-pandas py27-sympy py27-nose
I'm not sure if the default python installation is the one that I've been installing modules to, and if that may be the cause of a conflicting Unicode byte size compatibility error. In short, I've installed Numpy 1.7 using Python 2.7.3 and when I try to install this other program that uses Python and Numpy as dependencies, I get this error:
Traceback (most recent call last):
File "setup.py", line 20, in <module>
from weblogolib import __version__
File "/home/chris/Documents/IS/Bioinformatics-Software/weblogo-3.3/weblogolib/__init__.py", line 108, in <module>
from numpy import array, asarray, float64, ones, zeros, int32,all,any, shape
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString
So I guess I have a conflicting unicode byte size (2-byte vs. 4-byte). I went to check to see if I had conflicting versions of Python that could be messing this up.
python --version
Python 2.7.3
But this seems at odds with
which python
/usr/local/bin/python
When I go to /usr/local/bin I find these files (relevant to python):
python
python2
python2.7
python-config
python2-config
python2.7-config
Now I've installed numpy into the dist-packages directory of /usr/lib/python2.7/dist-packages which corresponds to what I get for python --version. But the fact that when I try which python and get a directory for python and not python2.7 concerns me that this might be conflicting when I try to install the program that uses python and numpy as dependencies.
So I guess to clarify my question(s): Are these normal files to find for a python installation or have I somehow installed three different versions? Could they be causing my error with the unrecognized symbol? Is there a way to uninstall if they are indeed extraneous versions?
Thanks for any help you can provide!
Oh and here is a link to a previous question I had, where I edited the PYTHONPATH while trying to fix an ImportError I was getting, if that might be affecting things....ImportError: No module named numpy
Here are the results of trying virtualenv:
chris#ubuntu:~/Documents/IS/Bioinformatics-Software$ virtualenv weblogo-3.3
New python executable in weblogo-3.3/bin/python
Installing setuptools.............done.
Installing pip...............done.
chris#ubuntu:~/Documents/IS/Bioinformatics-Software$ cd weblogo-3.3
chris#ubuntu:~/Documents/IS/Bioinformatics-Software/weblogo-3.3$ source bin/activate
(weblogo-3.3)chris#ubuntu:~/Documents/IS/Bioinformatics-Software/weblogo-3.3$ pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/lib/python2.7/dist-packages
Cleaning up...
The problem indeed seems to be a mismatch of Python and Numpy compile settings.
/usr/local/bin is where custom Python is installed, you should try to run using /usr/bin/python instead.
Another solution is to use a virtualenv. Try this:
virtualenv myproject
cd myproject
source bin/activate
pip install numpy
Basically virtualenv sets up a different Python installation with its own packages in the "myproject" directory. Running the "activate" command tells the system that you want to use this installation instead of the default system. This lets you have a different Python environment for different projects. Using virtualenv, each project can have its own versions of Python packages even if they're incompatible with other projects or system packages.
Note you will have to repeat the "source" command each time you open a new shell and want to use that virtual environment. Also you might have to install the virtualenv command by using your OS package manager. If this isn't possible (e.g. you don't have root access) or your OS version is too old for some reason, you can also download it manually from https://pypi.python.org/packages/source/v/virtualenv/
If you do ls -l /usr/local/bin/python* you should see that python and python2 are actually symlinks to python2.7, and likewise python-config and python2-config are symlinks to python2.7-config.
What OS are you on? This is more a question for superuser, but try something like this. Ditch easy_install and use pip if you haven't already.
On Ubuntu:
sudo apt-get install python-setuptools
sudo easy_install pip
pip install --user numpy