可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 import apt_pkg ImportError: No module named apt_pkg
What seems to be the problem and how can I resolve it?
回答1:
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
回答2:
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.
回答3:
Solve it by this:
/usr/lib/python3/dist-packages# cp apt_pkg.cpython-34m-i386-linux-gnu.so apt_pkg.so
回答4:
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 from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in import apport.fileutils File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in from apport.packaging_impl import impl as packaging File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in import apt File "/usr/lib/python3/dist-packages/apt/__init__.py", line 21, in 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.
回答5:
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)
回答6:
If you're using python 3.5, downgrade to 3.4. That's the safest move to do.
Under /usr/lib/python3/dist-packages you'll see *34m* which python 3.5 can't use. zhazha answer symlink to it.
回答7:
Just in case it helps another, I finally solved this problem, that was apparently caused by python version conflicts, by redirecting the link python3, then redirecting it to the right python version:
sudo rm /usr/bin/python3 sudo ln -s /usr/bin/python3.4
You may need to enter the correct python version, found with:
python3 -V