简体   繁体   English

Python 2无法正常工作,PYTHONPATH问题?

[英]Python 2 does not work any more, PYTHONPATH issue?

I use python3 normally but also some python2 with ROS. 我通常使用python3,但也使用带有ROS的python2。 After a longer time i tried to built my ros workspace and the error I get is 较长时间后,我尝试构建ros工作区,但出现的错误是

ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg'
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/safe_execute_process.cmake:11 (message):
execute_process(/home/work/py_venv/bin/python
"/opt/ros/kinetic/share/catkin/cmake/parse_package_xml.py"
"/opt/ros/kinetic/share/catkin/cmake/../package.xml"
"/home/work/catkin_ws/build/catkin_tools_prebuild/catkin/catkin_generated/version/package.cmake")

The first directory /home/work/py_venv/bin/python is a virtual environment for python3. 第一个目录/home/work/py_venv/bin/python是python3的虚拟环境。 I am not sure why it is looking there. 我不确定为什么要看那里。 I dont have any virtual environment activate (well on purpose at least). 我没有激活任何虚拟环境(至少是故意的)。 What I am totally missing though is the path to the standard python2 installation. 我完全缺少的是标准python2安装的路径。 Shouldnt it be there? 不应该在那里吗?

If I enter echo $PYTHONPATH in the terminal, I just get /opt/ros/kinetic/lib/python2.7/dist-packages I guess there is something missing? 如果我在终端中输入echo $PYTHONPATH ,我只会得到/opt/ros/kinetic/lib/python2.7/dist-packages我猜有什么丢失吗? How can I set this variable correctly. 如何正确设置此变量。 Which value does it have at installation? 安装时有什么价值? I recently installed venv in python3 apart from that I am not aware of any changes I did to python since it stoped working. 我最近在python3中安装了venv,除此之外我不知道我对python所做的任何更改,因为它停止工作了。

Now that is a lot of questions. 现在有很多问题。 If you can answer any of them, it would be appreciated. 如果您能回答其中任何一个问题,将不胜感激。

Edit: I know found the main problem is the prepending of the venv on the path , so that it look for the package in the python3 installation which does not contain the catkin package. 编辑:我知道发现主要问题是venv在path上的前置,因此它在python3安装中寻找不包含catkin软件包的软件包。 How can I remove this from the path? 如何将其从路径中删除?

If you want to remove venv python path, you can do that as follow, 如果您要删除venv python路径,可以按以下步骤进行操作,

echo $PATH
export PATH=<remove unwanted path>

In this way, you can remove your venv python path. 这样,您可以删除venv python路径。

Also, check this python --version which might be set to python3, if so change that as well. 另外,请检查此python --version ,它可能会设置为python3,如果是的话,也请进行更改。

Finally, check PYTHONPATH if it's not directed proper location change and try. 最后,检查PYTHONPATH是否未定向正确的位置更改,然后尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM