I am running Ubuntu 12.10 that has python 2.7 as its default. I have installed python 3.3 in /opt/python3.3 (using ./configure --prefix=/opt/python3.3) and have created a symlink /usr/bin/python33 that points to the executable in /opt. There is already a symlink /usr/bin/python3 that points to the python 3.2 (actually it points to python3.2mu: if you can explain as a side note as to why this 'mu' is included :) ) installation that came with the ubuntu installation.
I installed distribute tools using python3 without any problems. But when I tried the same thing with python33 it gave me the following error:
ankur#junk-mechanism:~$ sudo python33 distribute_setup.py
Extracting in /tmp/tmp685lyf
lzma module is not available
not a bzip2 file
gzip module is not available
bad checksum
Traceback (most recent call last):
File "distribute_setup.py", line 550, in <module>
sys.exit(main())
File "distribute_setup.py", line 547, in main
return _install(tarball, _build_install_args(options))
File "distribute_setup.py", line 78, in _install
tar = tarfile.open(tarball)
File "/opt/python3.3/lib/python3.3/tarfile.py", line 1578, in open
raise ReadError("file could not be opened successfully" + str(name) + repr(fileobj))
tarfile.ReadError: file could not be opened successfully/home/ankur/distribute-0.6.35.tar.gzNone
So in tarfile.py, the classmethod Tarfile.open calls the class method Tarfile.gzopen where the module gzip is imported:
try:
import gzip
gzip.GzipFile
except (ImportError, AttributeError):
raise CompressionError("gzip module is not available")
The error raised here is ImportError because gzip.py has an import zlib which it cant find. But even the other installations of python (2.7 and 3.2) dont contain zlib in the respective standard lib /usr/lib/pythonx.x/lib/. So what is the difference?
It sounds like you didn't build everything because of missing dependencies. You can try getting the missing dependencies and rebuilding. To get the missing dependencies, I'd just work from what Python 3.2 requires and do:
sudo apt-get build-dep python3
Then you can reconfigure and rebuild Python 3.3 to get all the required modules.
Another option is to use the dead snakes ppa:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.3
I usually install the -dev package too so that I can install packages that have C extension modules:
sudo apt-get install python3.3-dev
Related
I am working on a raspberry pi 3B+. I want to upgrade the python from 2.7 to 3.6.
I downloaded the python 3.6 extracted and made it, However it got installed in the /usr/local/bin.
I tried to make it again this time by specifying ./configure --prefix=/usr prefix however the make gave a traceback error.
I also tried update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2 which helps in changing versions of python.
However, after doing so, my pip is not working now.
I have the following files in /usr/local/bin:pip,pip2.7,pip3,pip3.5,pip3.6.
I tried removing pip so that i can reinstall it using sudo apt-get remove python-pip but it gives the following error:
pi#raspberrypi:/usr/local/bin $ sudo apt-get remove python-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libpython-all-dev python-all python-all-dev python-keyring
python-keyrings.alt python-secretstorage python-wheel
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
python-pip
0 upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
1 not fully installed or removed.
After this operation, 671 kB disk space will be freed.
Do you want to continue? [Y/n] y
Traceback (most recent call last):
File "/usr/bin/apt-listchanges", line 29, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
(Reading database ... 138007 files and directories currently installed.)
Removing python-pip (9.0.1-2+rpt2) ...
File "/usr/bin/pyclean", line 63
except (IOError, OSError), e:
^
SyntaxError: invalid syntax
dpkg: error processing package python-pip (--remove):
subprocess installed pre-removal script returned error exit status 1
Traceback (most recent call last):
File "/usr/bin/pycompile", line 35, in <module>
from debpython.version import SUPPORTED, debsorted, vrepr, \
File "/usr/share/python/debpython/version.py", line 24, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
dpkg: error while cleaning up:
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
python-pip
E: Sub-process /usr/bin/dpkg returned an error code (1)
which suggests that apt_pkg (or some problem with apt-get).
when i do pip --version , i get:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
ModuleNotFoundError: No module named 'pkg_resources'
I just want to have python 3.6 and 2.7(since i have already installed libraries on 2.7) with functional pip.
Why don't you install miniconda for ARM and get Python and all important packages at once ?
wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
sudo md5sum Miniconda3-latest-Linux-armv7l.sh
sudo /bin/bash Miniconda3-latest-Linux-armv7l.sh
sudo reboot -h now
I think you aren't aware that most linux distros come shipped with python2 AND python3. By typing python and pip you will use your operating systems python2 and pip2 version.
What you probably want is using python3 and pip3 instead.
Something like "upgrading" from python2 to python3 is not possible because it's a fundamental difference and they are incompatible. This is why you have both installed.
Uninstalling or upgrading your systems python interpreter is a terrible bad idea, because your system needs them. For professional usage you should think about version control again, but for your first (and second) steps in python it's totally fine to use the preinstalled python interpreter of your OS.
Solutions like pyenv or virtualenv are very powerfull tools, but you probably don't want to start with it.
I need to use CentOS 6.6 for a project which comes with Python 2.6 by default. When I install Swift it places the install inside /usr/lib/python2.6/site-packages/swiftclient/, so if I do a 'make altinstall' to install Python 2.7 or 3.3 it still runs with Python 2.6.
I read from other similar questions that trying to just install 2.7 or 3.3 on top of 2.6 will break yum.
The exception that occurs when running 'swift upload..' is:
Traceback (most recent call last):
File "/usr/bin/swift", line 7, in <module>
from swiftclient.shell import main
File "/usr/lib/python2.6/site-packages/swiftclient/__init__.py", line 20, in <module>
from .client import * # noqa
File "/usr/lib/python2.6/site-packages/swiftclient/client.py", line 136
return {key: safe_value(key, val) for (key, val) in headers}
^
SyntaxError: invalid syntax
Is there a way to install swift into the 2.7 directory? Is there some kind of environment variable I can change to point to Python2.7?
Thanks!
Obviously you can install swiftclient into python2.7 directory.
If you have installed python2.7 from sources with make altinstall you can then install pip2.7 and swiftclient
`
wget https://bootstrap.pypa.io/ez_setup.py
/usr/local/bin/python2.7 ez_setup.py
/usr/local/bin/easy_install-2.7 pip
/usr/local/bin/pip2.7 install swiftclient
The big deal though, is that you need to invoke explicitly python2.7 as the interpreter you want to use. Obviously you can set an env variable for it example export PYTHON27=/usr/local/bin/python2.7, but it has to be user/application specific and not system wide, 'cause as you already know, you will break yum dependencies.
Attempt to install psutils resulted a big headache...
$ python -V
Python 2.4.2
$ cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 4
$ cd psutil-2.1.1/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 17, in ?
from distutils.core import setup, Extension
ImportError: No module named distutils.core
Next - I try to install setuptools to use easy_install:
$ which easy_install
which: no easy_install
$ cd ../setuptools-1.4/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 12, in ?
from distutils.util import convert_path
ImportError: No module named distutils.util
Trying install distutils from ez_setup.py:
$ python ez_setup.py
Traceback (most recent call last):
File "ez_setup.py", line 278, in ?
main(sys.argv[1:])
File "ez_setup.py", line 210, in main
egg = download_setuptools(version, delay=0)
File "ez_setup.py", line 139, in download_setuptools
from distutils import log
ImportError: No module named distutils
So - how can I install it?
P.S. No, I haven't root on this machine and can't use package manager.
you need to run this (if Error happens on python3) ==> sudo apt-get install python3-distutils --reinstall
you need to run this (if Error happens on python2) ==> sudo apt-get install python2-distutils --reinstall
I have an answer here but I will copy it here
AskUbuntu answer:
Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. You should be able to do sudo apt install python3-distutils and it should work.
However, it did not work for me. I use Parrot OS, which is, as Ubuntu, Debian based. I upgraded my system and pip stopped working for python3.7, and I also got the error ModuleNotFoundError: No module named 'distutils.util'
I tried a lot of stuff to fix it and to reinstall distutils, and I found out by pure luck, that pip3, for python3.8 did work. I then tried python3.7 -m pip3 -V, got /usr/bin/python3.7: No module named pip3 so I decided to have a look in the /usr/lib files.
I looked at /usr/lib/python3/dist-packages and everything looked fine. Then I looked at /usr/lib/python3.7 and saw the folder distutil.
I opened it, and saw the __pycache__, the __init__.py file and a version.py file. I had no idea how many files should be in there, or what the code should be, but I knew that those two files were either wrong or missing another file.
Then I had a look at what was inside /usr/lib/python3.8/distutil and it was totally different. I found the following files:
command Folder
__pycache__ Folder
archive_util.py Python script
bcppcompiler.py Python script
cmd.py Python script
config.py Python script
core.py Python script
cygwinccompiler.py Python script
debug.py Python script
dep_util.py Python script
errors.py Python script
extension.py Python script
fancy_getopt.py Python script
filelist.py Python script
file_util.py Python script
__init__.py Python script
log.py Python script
msvc9compiler.py Python script
_msvccompiler.py Python script
msvccompiler.py Python script
README Plain text file
spawn.py Python script
sysconfig.py Python script
text_file.py Python script
unixccompiler.py Python script
util.py Python script
version.py Python script
versionpredicate.py Python script
This was a lot more promising, and since pip3 did work, I assumed that this distutils worked too, and I tried to copy it to the python3.7 folder by running this command:
sudo cp -r /usr/lib/python3.8/distutil /usr/lib/python3.7/distutil
Then I tried again python3.7 -m pip -V and got
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.7)
Then I tried installing some modules and everything works fine.
I hope this is helpful.
#ciro
I need to do even more to get virtualenv running again (upgraded from 18.04 to 20.04):
sudo cp /usr/lib/python3.8/_sysconfigdata__* /usr/lib/python3.6/
cd /usr/lib/python3.6
sudo ln -s _sysconfigdata_m_linux_x86_64-linux-gnu.py _sysconfigdata_m_x86_64-linux-gnu.py
I see this question asked all over the internet, and I've tried following them all, but I still can't get PIL to work.
I tried symbolically linking the zlib, jpeg, etc. libraries via:
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
I tried editing the setup.py file, adding this line:
add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
In fact, running $ sudo python setup.py install shows that JPEG, ZLIB/PNG, etc. support is Available. (I'm installing it for both 2.5 and 2.7, works in neither)
sudo python2.5 setup.py install
running install
running build
running build_py
running build_ext
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.5.6 (r256:88840, Feb 1 2012, 15:55:08)
[GCC 4.5.2]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
But after all that, I still get a decoder %s not available error.
I'm at my wits end. Anything else I might have missed?
My environment:
64-bit Ubuntu 11.04 running in a VirtualBox VM.
Here's what I do to test if PIL works or not
$ python
>>> from PIL import Image
>>> im = Image.open("photo.jpg")
>>> im.rotate(45)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1359, in rotate
self.load()
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 189, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 385, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available
>>>
As always, use the package manager:
sudo apt-get install python-imaging
It'll deal with it all for you. The packages are available.
Manually installing, in any Linux distro, is a wasted endeavour, unless the packages really don't exist. Package maintainers spend time ensuring that the package works and installs correctly, there is no point duplicating their effort. Especially not to manually install something that then doesn't have the advantages of a package - no automatic updating, no easy removal, etc...
I have successfully reinstalled PIL in Ubuntu 12.04 like this:
pip uninstall PIL
apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
pip install -U PIL
It does not raise the IOError: decoder zip not available anymore after reinstalling the PIL. My error traceback was:
Traceback (most recent call last):
File "convert_image.py", line 15, in <module>
image.save('output.png')
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1406, in save
self.load()
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 189, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 385, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available
Try reinstalling from scratch:
Look for lib/pythonXX/site-packages/PIL. Delete all this directory along with the file PIL.pth. This should completely remove te package.
Unpack the PIL installation files from the *tar.gz you downloaded.
Add the directories where your jpeg library is, with add_directory(...) as you did before.
(Use ldconfig -P | grep jpeg to find where the libraries are).
Retry python setup.py build, then python setup.py install. Test it.
My experience was:
Not performing step 2 did not rebuild the package.
Not performing step 3 was the root cause.
Not performing step 1 may have played a part.
This seems to be a bug in PIL installation, not in Ubuntu's or any distro's package structure.
And just for the record: it is quite common to have more than one Python version installed on a system, which makes it necessary to install packages manually. Some people have a 2.x with a 3.x for experimenting, shared hostings have 2.5s and applications need a 2.7, just to give two examples.
I found it to be a combination of the two above when installing with a requirements.txt on Ubuntu. I'm using Vagrant to run a chef script, and found this approach works best for me:
First, I use a bash script to setup PIL:
#!/usr/bin/env bash
sudo apt-get build-dep python-imaging
sudo ln -s -f /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/
sudo ln -s -f /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/
sudo ln -s -f /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/
Next, during the requirements.txt install, the top of the file looks like:
--allow-external PIL
--allow-unverified PIL
Django==1.5.4
PIL==1.1.7
...
Of course, this is an unsecured way of doing it, but works for dev and quick builds. For production, it's best to download and verify all packages manually and install them from a local managed repository.
I have a Mac running Python 2.6. When I try to use easy_install I get this message:
/usr/bin/easy_install-2.6:7: UserWarning: Module pkg_resources was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
from pkg_resources import load_entry_point
/usr/bin/easy_install-2.6:7: UserWarning: Module site was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
from pkg_resources import load_entry_point
Traceback (most recent call last):
File "/usr/bin/easy_install-2.6", line 10, in <module>
load_entry_point('setuptools==0.6c9', 'console_scripts', 'easy_install')()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 271, in load_entry_point
return False
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 2173, in load_entry_point
deps = []
ImportError: Entry point ('console_scripts', 'easy_install') not found
I am very confused by this and I want to know how I can fix this. Previously I didn't get this message, then after installing pip and uninstalling it, easy_install no longer works. I was wondering how I could fix this, or restore the default Python or easy_install setting on Mac.
Check your /usr/bin and /usr/local/bin for easy_install installations and remove any old script:
sudo rm -f /usr/bin/easy_install*
sudo rm -f /usr/local/bin/easy_install*
Download and run distribute:
curl -O https://svn.apache.org/repos/asf/oodt/tools/oodtsite.publisher/trunk/distribute_setup.py
sudo python distribute_setup.py
sudo rm distribute_setup.py
Try again, and enjoy. E.g.:
sudo easy_install pip
I suspect the easiest way you can get easy_install working again is to install distribute, which is an improved version of distutils that bundles it's own version of easy_install. Installation is simple:
curl -O http://python-distribute.org/distribute_setup.py
/usr/bin/python2.6 distribute_setup.py
I had the same problem just after installing the new Operating System (Lion OSX).
After install python and execute it
sudo easy_install ipython
ipython
I got the following error:
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 8, in <module>
load_entry_point('ipython==0.10.2', 'console_scripts', 'ipython')()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 318, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2220, in load_entry_point
raise ImportError("Entry point %r not found" % ((group,name),))
ImportError: Entry point ('console_scripts', 'ipython') not found
Then I realize it was a permission problem. If I execute the ipython script as sudo it worked.
sudo ipython
So I changed the ownership from root to my user () of the folder /Library/Python/2.7/site-packages/
sudo chown -R <your_user>:wheel /Library/Python/2.7/site-packages/
Use change ownership only if you don't have several accounts that uses python.
I hope it work for you.
Best
Your setuptools installation is broken. The easy_install-2.6 script in your /usr/bin directory, is only a wrapper that loads the actual easy_install module in your Python installation, and the latter is missing. Presumably uninstalling pip either broke the pointer to it (usually in the form of a .pth file in your site-packages directory) or removed the whole package but didn't remove the /usr/bin/easy_install-2.6 wrapper script.
Your best bet is to re-install setuptools from scratch again, by following the instructions on the setuptools PyPI page.
I had the same problem, I suspect caused by my installation of Homebrew which apparently installs its own version of easy_install blindly and screws up whatever you're currently running (enough times for homebrew to recognize it as a problem). I found my solution here Upgraded Python on Snowleopard Using Homebrew now pip and easy_install don't work
While I'm actually on Lion, it still fixed my problem. You just download ez_setup.py from http://pypi.python.org/pypi/ez_setup - run ez_setup.py through terminal and you're off to the races.
I had a similar error message after following similar steps. I suspect it's because I tried to install the distribute module, and it tried to install a new version of setuptools which
didn't quite work because it failed to correctly override the Mac OS X supplied setuptools. But that's only a suspicion.
I fixed my problem by doing the following. I found that the directory /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python
had 4 files with .OLD in the name. When I did a compare with similarly named files without the .OLD from when things worked (via Time Machine) I found that they were the same except for the name. So I did the following renames:
setuptools.OLD.1305936263.57 ->
setuptools
setuptools-0.6c9-py2.6.egg-info.OLD.1305936263.57 -> setuptools-0.6c9-py2.6.egg-info pkg_resources.py.OLD.1305936263.57
-> pkg_resources site.py.OLD.1305936263.59 -> site.py
I had to use the command line and sudo mv because the files are owned by root. For example: sudo mv setuptools.OLD.1305936263.57 setuptools. You'll have to enter your password.
The other thing I did was clean the /Library/Python/2.6/site-packages directory. I used Time Machine to set it back to its pre-messed up state. If you don't have Time Machine, then you should be able to recover if you delete any files or folders beginning with distribute, easy-install, pip, pkg_resources, setuptools and site.
If that doesn't do the trick, uninstall any modules you can from that directory. For example use pip uninstall if you installed modules with pip. The reason to do this is that installation can copy files into usr/local/bin and other places that pip will remove for you.
Next it's time to remove any remaining modules. Rename the folder (in case there's something you want later) and make a new empty one.
Reinstall the modules you want and with a little luck you're back in business...
Martijn Pieter's answer is correct.
Go to http://pypi.python.org/pypi/setuptools#downloads
Download setuptools-0.6c11-py2.7.egg
From your downloads directory run: sudo ./setuptools-0.6c11-py2.7.egg
Done :-)