问题
i am trying to install gensim using
sudo -H pip install --upgrade gensim
but it is giving me this error :
File "setup.py", line 301, in <module>
include_package_data=True,
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.7/dist-packages/setuptools/command /install.py", line 67, in run
self.do_egg_install()
File "/usr/local/lib/python2.7/dist-packages/setuptools/command /install.py", line 98, in do_egg_install
easy_install = self.distribution.get_command_class('easy_install')
File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 576, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2229, in load
return self.resolve()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 47, in <module>
from setuptools.sandbox import run_setup
File "/usr/local/lib/python2.7/dist-packages/setuptools/sandbox.py", line 15, in <module>
import pkg_resources.py31compat
ImportError: No module named py31compat
please help me, in installing gensim. i googled it, but i am not able to find the solution.
回答1:
It looks like setuptoopls is missing. Try
$sudo pip install setuptools
回答2:
Notice that setuptools
come from /usr/local/lib
whereas pkg_resources
come from /usr/lib
. You must likely have an older pkg_resources through the package system and then a newer setuptools installed by pip.
Delete (or move away) the /usr/local/lib/python2.7/dist-packages/setuptools
directory.
回答3:
I encountered a very similar error upon an Ansible run of a refactored OpenShift playbook. The error was discovered once all of the plays were parsed.
"ERROR! Unexpected Exception, this is probably a bug: cannot import name py31compat"
I am using ...
- Ansible 2.5.3
- Python2-2.7.15
I ran the following command to list the location of all of the packages and libraries associated with Python 2. I checked available paths to ensure I had one version of Ansible and one copy of each package installed.
$ python -c 'import sys; print sys.path'
'py31compat' is not a separate module one can download. It is included with the Setuptools package. It was determined I had two packages installed of different versions, both out-of-date. I uninstalled both via pip and installed the latest setuptools version available. No luck.
My solution was to uninstall Ansible and reinstall the same version. This resolved the issue.
回答4:
In my case i have odoo v10 installed and for any weird reason update or installed a library that stuck my server and not longer to start with XOE.
The error was:
cannot import name py31compat
After 1 hour trying many differents things i decide uninstall:
sudo pip uninstall setuptools
Uninstalling setuptools-40.8.0: Would remove: /usr/local/bin/easy_install /usr/local/bin/easy_install-2.7 /usr/local/lib/python2.7/dist-packages/easy_install.py /usr/local/lib/python2.7/dist-packages/pkg_resources/* /usr/local/lib/python2.7/dist-packages/setuptools-40.8.0.dist-info/**
And my service odoo server starts and works fine again!
来源:https://stackoverflow.com/questions/46998858/importerror-no-module-named-py31compat