zlib cannot be installed using yum - python

I am working on a RHEL system. I have two versions of Python installed on my system: Python 2.4 and Python 2.7, but I have created an alias in the .bashrc file so that the python command prompts Python 2.7 instead of Python 2.4.
I need to install zlib in my system. I tried to install it using the yum command:
yum install zlib
yum install zlib-devel
both worked fine, but when I type "python", I still cannot see zlib installed:
[root#mymachine]# python
Python 2.7 (r27:82500, Jan 18 2012, 17:03:29)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named zlib
But if I import zlib from Python 2.4, it works! Why? I need zlib to be installed using Python 2.7. How can I do that? Thank you in advance!

Generally you will only find RPMs for the default Python version in the yum repository, however that shouldn't really be applicable here since zlib should be installed by default in your Python 2.7 installation.
Check sys.path using import sys; print sys.path and make sure that you have the lib directories for your Python 2.7 installation, it is possible that whatever you are doing in .bashrc is causing you to pick up the Python 2.4 environment.
Here is the location of my zlib module, which may be useful in trying to track down the location of yours so you can make sure it is on sys.path.
>>> import zlib
>>> zlib
<module 'zlib' from '/usr/local/lib/python2.7/lib-dynload/zlib.so'>
If you cannot find it then you should reinstall Python 2.7.

The zlib and zlib-devel packages are the C shared and development libraries, respectively; the zlib you are importing in Python 2.4 is the one that shipped in the python-libs package:
$ rpm -qf /usr/lib64/python2.4/lib-dynload/zlibmodule.so
python-libs-2.4.3-46.el5
I don't know where you got your Python 2.7 from, but zlib is part of the standard library--it should have been built with Python. You will need to acquire a zlib module that was built against Python 2.7.

Related

installed pytorch1.0.1 for OS X with pip3 but cannot import, what can I do?

I have already installed pytorch for MacOS 10.14 with pip3, but I can not import it in the python script. What should I do?
System: MacOS 10.14
Python3: v3.7
➜ ~ pip3 list
Package Version
----------- -----------
numpy 1.16.2
Pillow 5.4.1
pip 18.1
pycairo 1.17.1
pygobject 3.28.3
setuptools 40.5.0
six 1.12.0
torch 1.0.1.post2
torchvision 0.2.2.post3
virtualenv 16.1.0
wheel 0.32.2
➜ ~ python3
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
>>>
To expand upon my comment:
There's no strict guarantee that a pip3 wrapper script somewhere on your system is related to the pip package manager/module for your python3 binary. That wrapper may be created by a different installation of Python – maybe your system's own, maybe something else. (You can see where the script is located with which pip3 and see which interpreter it uses with less $(which pip3) and looking at the shebang line at the top.)
Each version of Python you have installed has its own site-packages directory, which contains the globally (as far as that version is concerned) installed packages. Fortunately, pip can be run exactly equally as the wrapper script would with the -m switch, so to be sure Torch and Torchvision get installed into your python3 (which appears to be Python 3.7.0 at this time),
python3 -m pip install torch torchvision
should do the trick.
However, globally (well, interpreter-globally, as discussed above) installed packages should be avoided, since you can easily get into hairy conflicts when you're working on multiple projects. You should instead use virtualenvs to separate your library installations from each other – the venv module is included in Python these days, and the official documentation has a guide on it. (Other options are pipenv and poetry, but it's worth knowing the lower-level tooling.)

'setuptools' module not contained in python 3.4?

I was trying to import setuptools in Python3.4 as following,
>>> from setuptools import setup
But I got the ImportError: No module named 'setuptools'.
My current version of Python3.4 is Python 3.4.0b1 (default, Nov 29 2013, 16:37:17), and it is installed using MacPorts.
So there is no setuptools module contained in Python 3.4 Standard Library, right? and I need to install setuptools module through pip?
Update:
setuptools is not in the standard library. But I cannot install it through pip because pip need setuptools installed first. MacPorts contains py34-setuptools #2.0.2 port and I can install setuptools through it.
setuptools has never been a part of the standard lib. You'll always to download it separately.
For 3.4, download setuptools - (This is the compressed download link!), extract it and install it via:
python setup.py install
You'll have to install it yourself. If you've got a completely empty environment in a new python installation, have a look at the official install instructions.
It works for me, but I'm using 3.4b2 on a Linux Mint system:
$ /usr/local/cpython-3.4/bin/python
Python 3.4.0b2 (default, Jan 5 2014, 13:53:24)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from setuptools import setup
>>>

solaris python setuptools install

I have a solaris host:
SunOS blah 5.10 Generic_147441-27 i86pc i386 i86pc
and I have python at /usr/bin/python
$ /usr/bin/python
Python 2.6.4 (r264:75706, Jun 26 2012, 21:27:36) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>>
the problem is that I do not appear to have setuptools installed, so I download the tarball and try:
setuptools-0.6c12dev-r88846$ /usr/bin/python setup.py install
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from distutils.util import convert_path
ImportError: No module named distutils.util
and of course, because I don't have distutils, I can't install... well anything.
I'm not familiar with solaris at all; some googling indicated that I need python-dev installed. how do I do that? any other suggestions?
You can use Python from OpenCSW. There you'll get a Python package and many modules, including setuptools. Available Python versions are Python 2.6 (CSWpython), 2.7 (CSWpython27) and 3.3 (CSWpython33). Most module packages are available for Python 2.6 and 2.7. Assuming you've got started with OpenCSW and added /opt/csw/bin to PATH, you can:
sudo pkgutil -y -i python py_django
To get modules for Python 3.3, can use virtualenv and pip as a regular user. For example:
sudo pkgutil -y -i python33 virtualenv
virtualenv -p /opt/csw/bin/python3.3 py3env
source py3env/bin/activate
pip install django

Can't install module with python-pip properly

I would like to install a module but pip is not installing it in the right directory which I assume should be /usr/local/lib/python2.7/site-packages/. After all, I just installed Python 2.7.2 today. Originally I had 2.6.5 and had installed modules successfully there. So I think something is wrong with my Python path.
How to have all my module installations go to the proper python2.7 directory?
s3z#s3z-laptop:~$ pip install requests
Requirement already satisfied: requests in /usr/local/lib/python2.6/dist-packages/requests-0.6.1-py2.6.egg
Installing collected packages: requests
Successfully installed requests
s3z#s3z-laptop:~$ python
Python 2.7.2 (default, Oct 1 2011, 14:26:08)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
>>> ^Z
[3]+ Stopped python
Also here is what my Python directories look like now http://pastie.org/2623543
After you installed Python 2.7, did you install the Python 2.7 version of easy_install and PIP? The existing installations are configured to use Python 2.6 by default which may be causing your issue.
You are probably using pip linked to python2.6, instead of 2.7. If you have installed pip properly with python2.7, you can do:
pip-2.7 install requests
If not, try installing this way:
curl -O http://python-distribute.org/distribute_setup.py
[sudo] python2.7 distribute_setup.py
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
[sudo] python2.7 get-pip.py

Installing Pygame for Python 3.1.2 in Ubuntu

I'm reading the book Introduction to Computer Science Using Python and Pygame by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1.9.1), Python 3.1.2 can't import pygame.
Python 3.1.2 (r312:79147, Sep 27 2010, 09:45:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygame
Python 2.6.5 imports it without fuss, however,
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>>
Are you aware of any issues for Linux/Ubuntu's Python 3.1.2 (Prof. Craven used Windows in his book)? How come Pygame 1.9.1 worked for Python 3.1.3 but not for 3.1.2?
Thanks for any pointers. (--,)
PyGame on Python 3 remains experimental, but these steps worked for me on Ubuntu 11.10:
sudo apt-get install mercurial python3-dev libjpeg-dev libpng12-dev libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev libx11-dev ttf-freefont libavformat-dev libswscale-dev
hg clone -u 01b2cb16dc17 https://bitbucket.org/pygame/pygame
cd pygame
python3 config.py
2to3 setup.py -w
python3 setup.py build
sudo python3 setup.py install
(You may remove the -u 01b2cb16dc17 to try the latest version; 01b2cb16dc17 worked for me.)
I hate to re-open an old post, but I had the hardest time installing pygame with a version of python that was not Ubuntu's default build. So I created this tutorial/ how to:
Install python3.1 and pygame1.9.1 in Ubuntu
I hopes this helps the next unfortunate soul to try this.
I installed pygame for python3 quite easily using the pip3 (a tool for installing and managing Python packages) command on Ubuntu 16.04.7 LTS.
Open a terminal and install pip3, type sudo apt install python3-pip
Now use it to install pygame for python3, type pip3 install pygame
That's it! Import the library and confirm that everything works:
# I'll try it out using the python 3 interpreter.
python3 --version
Python 3.5.2
robert#robert-E7212:~/Source/Python/python_crash_course/alien_invasion$ python3
Python 3.5.2 (default, Oct 7 2020, 17:19:02)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
# No errors, pygame was imported successfully!
>>> import pygame
pygame 2.0.0 (SDL 2.0.12, python 3.5.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>
I followed #Søren 's method, but without the -u number.
The only complication was a few compilation errors at the last line, all due to syntax and unicode differences between Python 2 and Python 3, but with a little checking of the web documentation it was a matter of a few minutes with a text editor modifying the following files (all paths are relative to the pygame directory created during the download):
gedit build/lib.linux-x86_64-3.2/pygame/colordict.py
gedit build/lib.linux-x86_64-3.2/pygame/tests/test-utils/png.py
gedit build/lib.linux-x86_64-3.2/pygame/examples/movieplayer.py
The line numbers from the compiler error messages are great for giving you where to start. The things to look out for are:
1 remove all references to u"xxxx" colours
2 use Python3 syntax for exceptions
3 change all print commands to Python3 equivalents
Then re-issue the final compilation command:
sudo python3 setup.py install
If you miss one or two or get it wrong, just keep going round the loop editing and re-compiling till it works.
BTW I deliberately did not give details of the compiler messages, because I expect they will depend on the current build you download. The files I needed to change were for version '1.9.2pre' downloaded as of the date on this post.
Just use the below command to install pygame for Python3. I could install pygame correctly on Ubuntu 16.04 and Python Python 3.5.2.
pip3 install pygame
It's because installing the python-pygame package installs it for the default version of Python on your system, 2.6.5 in this case. You should download the pygame package and use setup.py to install it in 3.1.2.
The python-pygame package is only compiled for python2.6 and python2.7 where I am. You'll have to install it again, possibly from a python3 branch of the source.

Categories

Resources