问题描述:

I got stuck in a problem. I am Debian user, and I want to install python-dev, but when I run the code in the shell as a root:

# aptitude install python-dev

I get the following error:

Traceback (most recent call last):

File "/usr/bin/apt-listchanges", line 28, in <module>

import apt_pkg

ImportError: No module named apt_pkg

What seems to be the problem and how can I resolve it?

Thanks in advance!

网友答案:

Make sure you have a working python-apt package. You could try and remove and install that package again to fix the problem with apt_pkg.so not being located.

apt-get install python-apt
网友答案:

I recently encountered the same problem whenever I run a Python 3.3.0 script in Aptana Studio using Ubuntu Quantal. Aside from the error from the script I'm working on, I get the following intermingled with it:

Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, in 
    apport_excepthook from apport.fileutils import likely_packaged,
    get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 4, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in 
    <module> from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in 
    <module> import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 21, in <module>
    import apt_pkg
ImportError: No module named 'apt_pkg'

I tried removing, cleaning, purging, and reinstalling python3-apt, and kind of snooping around a bit, and I found that the error is only affecting Python 3.3.0. Trying to import apt_pkg in IDLE barks the same error. Interestingly, importing this using IDLE with Python 3.2.3 works fine. Additionally, both version of Python 3.x.x share the same /usr/lib/python3/dist-packages, and in it there's apt_pkg.cpython-32mu.so and apt_pkg.cpython-32dmu.so. Are these file just not compatible with Python 3.3.0?

One last thing, running the script outside of Aptana Studio gives me my script's error without the ImportError: No module named 'apt_pkg' message.

网友答案:

I met this problem when doing sudo apt-get update. My env is debian8, with python2.7 + 3.4(default) + 3.5.

The following code will only re-create a apt_pkg....so file for python 3.5

sudo apt-get install python3-apt --reinstall

The following code solved my problem,

cd /usr/lib/python3/dist-packages
sudo ln -s apt_pkg.cpython-{35m,34m}-x86_64-linux-gnu.so

So, obviously, python3-apt checks the highest python version, instead of the current python version in use.

网友答案:

For some reason my install was missing apt_pkg.so in the python3 dist-packages dir. (apt_pkg.cpython-33m-x86_64-linux-gnu.so was there?!) but and I had to make a symlink apt_pkg.so -> apt_pkg.cpython-33m-x86_64-linux-gnu.so in /usr/lib/python3/dist-packages

I'm not sure whether my upgrade was broken or why this was the case. It occured after trying to upgrade (precise->raring->quantal upgrade)

相关阅读:
Top