Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I run a Slackware system and I'm trying to run some Python code, but getting a lot of errors such as this one below:

>>> import urllib2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/urllib2.py", line 91, in <module>
    import hashlib
  File "/usr/lib/python2.6/hashlib.py", line 136, in <module>
    md5 = __get_builtin_constructor('md5')
  File "/usr/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor
    import _md5
ImportError: No module named _md5

urllib2 should be a rather basic lib with Python, how can I get Python working correctly?

Reason being is that urllib2 seems to be a dependancy of praw: https://github.com/praw-dev/praw/issues/135

Trying to install pip to get this installed gives me:

Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    from setuptools import setup
ImportError: No module named setuptools

So I tried installing setuptools:

running install
Traceback (most recent call last):
  File "setup.py", line 94, in <module>
    scripts = scripts,
  File "/usr/lib/python2.6/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib/python2.6/distutils/dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.6/distutils/dist.py", line 995, in run_command
    cmd_obj.run()
  File "/root/setuptools-0.6c11/setuptools/command/install.py", line 76, in run
    self.do_egg_install()
  File "/root/setuptools-0.6c11/setuptools/command/install.py", line 85, in do_egg_install
    easy_install = self.distribution.get_command_class('easy_install')
  File "/root/setuptools-0.6c11/setuptools/dist.py", line 395, in get_command_class
    self.cmdclass[command] = cmdclass = ep.load()
  File "/root/setuptools-0.6c11/pkg_resources.py", line 1954, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/root/setuptools-0.6c11/setuptools/command/easy_install.py", line 21, in <module>
    from setuptools.package_index import PackageIndex, parse_bdist_wininst
  File "/root/setuptools-0.6c11/setuptools/package_index.py", line 2, in <module>
    import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO
  File "/usr/lib/python2.6/urllib2.py", line 91, in <module>
    import hashlib
  File "/usr/lib/python2.6/hashlib.py", line 136, in <module>
    md5 = __get_builtin_constructor('md5')
  File "/usr/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor
    import _md5
ImportError: No module named _md5
share|improve this question
    
did you try to install pip from pypi.python.org/pypi/pip, do you have easy_install in your system. try downloading setuptools as tar.gz and then try installing it. –  harish.venkat Oct 30 '12 at 19:33
    
@harish.venkat Yes, that's what I did; see the bottom part of my question where it fails due to _md5 –  Zeno Oct 30 '12 at 19:47
    
"stackoverflow.com/questions/10306531/…; "johnsofteng.wordpress.com/2009/06/21/…; see this whether this helps –  harish.venkat Oct 31 '12 at 15:14
add comment

2 Answers 2

up vote 3 down vote accepted

You can use pip or easy_install to install python modules.

 $ pip install <package-name>

Edit:

I tried installing urllib2 package and it told me that the real name of requirement urllib2 is urllib3. Here is the what it happened:

pradeep@pradeep-laptop:~$ sudo pip install urllib2
Downloading/unpacking urllib2
  Real name of requirement urllib2 is urllib3
  Could not find any downloads that satisfy the requirement urllib2
No distributions at all found for urllib2
Storing complete log in /home/pradeep/.pip/pip.log
pradeep@pradeep-laptop:~$ sudo pip install urllib3
Downloading/unpacking urllib3
  Downloading urllib3-1.5.tar.gz
  Running setup.py egg_info for package urllib3

Installing collected packages: urllib3
  Running setup.py install for urllib3

Successfully installed urllib3
Cleaning up...
pradeep@pradeep-laptop:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3
>>> 

Edit2:

You can install python-pip from source.

$ wget http://pypi.python.org/packages/source/p/pip/pip-0.7.2.tar.gz
$ tar xzf pip-0.7.2.tar.gz
$ cd pip-0.7.2
$ python setup.py install
share|improve this answer
    
I get command not found on either of those. –  Zeno Oct 30 '12 at 18:52
    
@Zeno: Hey you dont have pip installed in your Slackware. I think you can try sudo installpkg python-pip –  pradeepchhetri Oct 30 '12 at 18:59
    
I tried that and got sudo installpkg python-pip Cannot install python-pip: package does not end in .tgz –  Zeno Oct 30 '12 at 19:00
    
@Zeno: I think you can install from tarball using the instructions given in this link: guide.python-distribute.org/… –  pradeepchhetri Oct 30 '12 at 19:02
    
Okay, tried that and it's giving me ImportError: No module named setuptools... so I tried installing setuptools and got ImportError: No module named _md5` See my edited question for full details –  Zeno Oct 30 '12 at 19:04
show 4 more comments

Pip is the right way to go in order to install your Python modules. Easy_installer is the default python package installer, but pip replaces it, and should normally be preferred, though a few packages will only install with easy_installer.

Where other answers are breaking down, here, is how to install software on a slackware machine. Rather than building new software yourself, you should check out Slackbuilds.org. This repository shares a link to the software source, and a custom build script for Slackware to compile the software and make a Slackware package that can easily be installed/uninstalled/upgraded, and is tracked by Slackware's package management system, installpkg/updatepkg/removepkg. Slackbuilds will also let you know of dependencies on other slackbuilds packages. Please note, slackbuilds assumes a comprehensive Slackware installation, and doesn't tell you any dependencies on the standard slack packages.

Assuming Slack 14.0, you will need: http://slackbuilds.org/repository/14.0/python/pip/ http://slackbuilds.org/repository/14.0/python/distribute/

Finally, please look into slackpkg and sbopkg for more comprehensive automated package management for Slackware. Slackware officially doesn't support slackpkg, or slackbuilds, though they are widely used and well maintained.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.