[英]Python module not found error "No module named 'ortools' "
I'm new to python and or-tools.我是 python 和 or-tools 的新手。 I'm trying to run thissample program from Google OR-Tools.
我正在尝试从 Google OR-Tools 运行此示例程序。
I've installed or-tools by python -m pip install --upgrade --user ortools
and copied full script from the link, and added #!/usr/bin/env python3
and did chmod +x tsp.py
.我已经通过
python -m pip install --upgrade --user ortools
安装了 or-tools 并从链接复制了完整脚本,并添加了#!/usr/bin/env python3
并执行了chmod +x tsp.py
。
After running the script, this error showed up:运行脚本后,出现此错误:
Traceback (most recent call last):
File "tsp.py", line 5, in <module>
from ortools.constraint_solver import routing_enums_pb2
ModuleNotFoundError: No module named 'ortools'
First, I thought this is because PYTHONPATH, so did :首先,我认为这是因为 PYTHONPATH,所以:
export PYTHONPATH="./.local/lib/python2.7/site-packages/ortools"
But the error text didn't changed.但是错误文本没有改变。 If anyone knows what it cause, help me please.. Thank you
如果有人知道这是什么原因,请帮助我..谢谢
-----------UPDATE----------------------- - - - - - -更新 - - - - - - - - - - - -
After I got comments, I ran python -m site
This is showed up.收到评论后,我运行
python -m site
这出现了。
ros@ros-dynabook-R734-M:~/tsp$ python -m site
sys.path = [
'/home/ros/tsp',
'/opt/ros/melodic/lib/python2.7/dist-packages',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/ros/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/wx-3.0-gtk3',
]
USER_BASE: '/home/ros/.local' (exists)
USER_SITE: '/home/ros/.local/lib/python2.7/site-packages' (exists)
ENABLE_USER_SITE: True
I also went to ~/python2.7/site-packages/ and ~/python3.6/dist-packages/, but there is no ortools module..我也去了~/python2.7/site-packages/和~/python3.6/dist-packages/,但是没有ortools模块..
I needed to install 'OR-Tools' by python3 -m pip install --upgrade --user ortools
to use in python3.我需要通过
python3 -m pip install --upgrade --user ortools
安装“OR-Tools”以在 python3 中使用。 And also PYTHONPATH should be the parent directory of the packages which is ./.local/lib/python2.7/site-packages/
.而且 PYTHONPATH 应该是包的父目录,即
./.local/lib/python2.7/site-packages/
。
Now the script seems running correctly.现在脚本似乎运行正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.