在我公司的服务器上,我尝试运行Python脚本。然而它告诉我sklearn丢失了,但它在/usr/local/lib/python2.7/dist-packages
:~/Eclipse-Stats$ python Main.py
2017-07-24 14:01:55.852751
Traceback (most recent call last):
File "Main.py", line 2, in <module>
import kmeans
File "/home/ubuntu/Eclipse-Stats/kmeans.py", line 3, in <module>
import sklearn
ImportError: No module named sklearn
:~/Eclipse-Stats$ pip install -U scikit-learn
Requirement already up-to-date: scikit-learn in /usr/local/lib/python2.7/dist-packages
也许它认为它不在服务器上,但是当我尝试安装它时,它会将它安装在已经拥有它的笔记本电脑上?
我在服务器上安装了Python 2.7.13。这似乎是问题,因为当我运行wiyt python3
它似乎工作:
~/Eclipse-Stats$ python3 Main.py
File "Main.py", line 113
print "list of groups you can recommend : "
^
SyntaxError: Missing parentheses in call to 'print'
但是该网站的西班牙语版本(FJSevilla)的Python专家告诉我它不确定。
我试图从python解释器导入它:
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sklearn
所以我尝试卸载,清除并重新安装它(我不记得在提示时我想到的地方):
sudo apt-get install build-essential python-dev python-setuptools python-numpy python-scipy libatlas-dev libatlas3-base
...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
然后我尝试再次导入它但失败了:
>>> import kmeans
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "kmeans.py", line 3, in <module>
import sklearn
ImportError: No module named sklearn
>>> kmeans.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'kmeans' is not defined
并且:
>>>sudo pip install -U scikit-learn
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sklearn
我最近的尝试是根据this answer from boshea in 2013
授予权限问题ubuntu@ip-172-31-41-89:~/Eclipse-Stats$ sudo chmod -R go+rX /usr/local/lib/python2.7/dist-packages
ubuntu@ip-172-31-41-89:~/Eclipse-Stats$ python
Python 2.7.13 (default, Jul 24 2017, 09:52:34)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sklearn
FJSevilla建议查看是否已在系统级安装了sklearn:
pip install --user --install-option="--prefix=" -U scikit-learn
/home/ubuntu/.local/lib/python2.7/site-packages/pip/commands/install.py:194: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
cmdoptions.check_install_build_global(options)
Requirement already up-to-date: scikit-learn in /usr/local/lib/python2.7/dist-packages
$ ls /usr/local/lib/python2.7/dist-packages/sklearn
__check_build exceptions.pyc multiclass.py
__init__.py externals multiclass.pyc
__init__.pyc feature_extraction multioutput.py
_build_utils feature_selection multioutput.pyc
_isotonic.so gaussian_process naive_bayes.py
base.py grid_search.py naive_bayes.pyc
base.pyc grid_search.pyc neighbors
似乎安装没问题但是翻译没有查看正确的文件夹...