如何在终端和 PyCharm 上使用相同的 Python 解释器?

如何在终端和 PyCharm 上使用相同的 Python 解释器?

我想使用 PyCharm 而不是通过终端运行一些脚本python turtlebotrun.py

当我运行它时从终端它正在工作但是当我在 PyCharm 上运行它时它说

/usr/bin/python2.7 /home/ros/Desktop/project/turtlebotrun.py
Traceback (most recent call last):
  File "/home/ros/Desktop/project/turtlebotrun.py", line 2, in <module>
    from turtlebot import Turtlebot
ImportError: No module named turtlebot

Process finished with exit code 1

我在 PyCharm 设置中使用与sys.path终端上显示的相同的解释器路径。版本均为 2.7。

我该如何解决这个问题?我使用的是同一个解释器吗?我该如何检查?

更新 1: 有多个路径。我把这些都添加到了 pycharm 中,但什么都没有。我sys.path在同一个文件上使用,第一个我通过终端执行,第二个用 Pycharm 执行

终端:

    ros@xxxxx:~/Desktop/project$ python turtlebotrun.py
    ['/home/ros/Desktop/project',
     '/home/ros/ros_ws/devel/lib/python2.7/dist-packages', 
     '/opt/ros/kinetic/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/PILcompat', 
     '/usr/lib/python2.7/dist-packages/gtk-2.0', 
     '/usr/lib/python2.7/dist-packages/wx-3.0-gtk2']

Pycharm:

>>> import sys
>>> print(sys.path)
/usr/bin/python2.7 /home/ros/Desktop/project/turtlebotrun.py
['/home/ros/Desktop/project',
 '/home/ros/Desktop/project/turtlebotrun.py', 
 '/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/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0', 
 '/usr/lib/python2.7/dist-packages/wx-3.0-gtk2']

 Process finished with exit code 0

正如您在结果中看到的那样,这些目录丢失的即使添加到 pycharm 设置中的路径中

/home/ros/ros_ws/devel/lib/python2.7/dist-packages, /opt/ros/kinetic/lib/python2.7/dist-packages

所以问题是:为什么这些目录没有被使用?
也许这就是为什么无法从 PyCharm 运行脚本的原因

相关内容