简体   繁体   English

如何使用py2和py3在eclipse中运行python?

[英]how to run python in eclipse with both py2 and py3?

pre: 前:

  1. I installed both python2.7 and python 3.70 我同时安装了python2.7和python 3.70
  2. eclipse installed pydev, and configured two interpreters for each py version eclipse安装了pydev,并为每个py版本配置了两个解释器
  3. I have a project with some py scripts 我有一个带有一些py脚本的项目

question: 题:

I choose one py file, I want run it in py2, then i want it run in py3(manually). 我选择一个py文件,我想在py2中运行它,然后我希望它在py3中运行(手动)。

I know that each file cound has it's run configuration, but it could only choose one interpreter a time. 我知道每个文件库都有它的运行配置,但是一次只能选择一个解释器。

I also know that py.exe could help you get the right version of python. 我也知道py.exe可以帮助您获取正确版本的python。

I tried to add an interpreter with py.exe, but pydev keeps telling me that "python stdlibs" is necessary for a interpreter while only python3's lib shows up. 我试图用py.exe添加解释器,但是pydev一直告诉我,解释器需要“ python stdlibs”,而只有python3的lib出现。

so, is there a way just like right click the file and choose "run use interpreter xxx"? 因此,有没有一种方法类似于右键单击文件并选择“运行使用解释器xxx”? or, does pydev has the ability to choose interpreters by "#! python2"/"#! python3" at file head? 或者,pydev是否可以在文件头通过“#!python2” /“#!python3”选择解释器?

I didn't understand what's the actual workflow you want... 我不明白您想要的实际工作流程是什么...

Do you want to run each file on a different interpreter (say you have mod1.py and want to run it always on py2 and then mod2.py should be run always on py3 ) or do you want to run the same file on multiple interpreters (ie: you have mod1.py and want to run it both on py2 and py3 ) or something else? 您是否要在不同的解释器上运行每个文件(例如,您拥有mod1.py并希望始终在py2上运行它,然后mod2.py应该始终在py3py3 )还是要在多个解释器上运行同一文件? (即:您有mod1.py并想同时在py2py3上运行它)或其他东西?

So, please give more information on what's your actual problem and what you want to achieve... 因此,请提供有关您的实际问题和您想要实现的目标的更多信息。


Options to run a single file in multiple interpreters: 在多个解释器中运行单个文件的选项:

  1. Always run with the default interpreter (so, make a regular run -- F9 to run the current editor -- change the default interpreter -- using Ctrl+shift+Alt+I -- and then rerun with Ctrl+F11 ). 始终使用默认解释器运行(因此,请定期运行F9以运行当前编辑器-更改默认解释器-使用Ctrl+shift+Alt+I然后使用Ctrl+F11重新运行)。

  2. Create a .sh / .bat which will always do 2 launches (initially configure it to just be a wrapper to launch with one python, then, after properly configuring it inside of PyDev that way change it to launch python 2 times, one with py2 and another with py3 -- note that I haven't tested, but it should work in theory). 创建一个始终执行2次启动的.sh / .bat (最初将其配置为仅作为包装器以使用一个python启动,然后在PyDev内部正确配置该方式后将其更改为以python 2次启动,一次使用py2另一个使用py3-请注意,我尚未测试过,但理论上应该可以使用)。

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

相关问题 如何编写用于处理py2和py3的URLError异常的python代码 - How do I write python code that handles URLError Exception for both py2 and py3 如何在Python中以与py2和py3一起使用的方式定义二进制字符串? - How to define a binary string in Python in a way that works with both py2 and py3? 在 py2 和 py3 中处理 Python 文件读取选项 rU 的优雅方式 - Elegant way to handle Python file read option rU in both py2 and py3 如何以适用于py2和py3的方式将对象转换为Unicode? - How to convert an object to Unicode in a way that works in both py2 and py3? 如何处理python导入,以便它们与py2和py3轻松配合? - How to deal with python imports so they work easily with py2 and py3? 将硒从Py3更改为Py2 - Changing Selenium from Py3 to Py2 在Py3而不是Py2上嵌套了“ ImportError” - Nested `ImportError` on Py3 but not on Py2 Py2 到 Py3:添加未来的导入 - Py2 to Py3: Add future imports 如何创建一个类似List的类,该类允许在与py2和py3一起使用的切片上调用包含的对象方法 - How to create a List like class which allows calling contained objects methods on slices which work with both py2 and py3 Django中不再识别带有前导点的Python导入从py3到py2 - Python imports with leading dot no longer recognised going from py3 to py2 in django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM