简体   繁体   English

在一个脚本中运行两个版本的Python。 可能?

[英]Running two versions of Python in one script. Possible?

I have a pure Python 3.7.3 and another Python 3.7.0 that comes with QGIS software bundle. 我有一个纯Python 3.7.3和另一个附带QGIS软件包的Python 3.7.0。

I set default Python as 3.7.0 and need to get some functions and modules working in 3.7.3. 我将默认Python设置为3.7.0,并且需要在3.7.3中使用一些函数和模块。

I could set my default environment to a 3.7.3 but in this case I can not get an access to qgis.core lib. 我可以将我的默认环境设置为3.7.3,但在这种情况下,我无法访问qgis.core lib。 In 3.7.0 I need to perform from PyQt5 import QtWidgets but here it throws and error of missing dll. 在3.7.0中,我需要from PyQt5 import QtWidgets执行from PyQt5 import QtWidgets但在这里抛出并丢失dll的错误。 Re-installing pyqt5 will harm qgis and totally delete it. 重新安装pyqt5会损害qgis并完全删除它。

So I see that I need to run scripts from 3.7.0 with Qt functions that work in pure 3.7.3. 所以我看到我需要从3.7.0运行脚本,Qt函数在纯3.7.3中运行。 But how can I put in my script. 但是我怎么能把我的脚本放进去。 I tried to test virtualenv but looks like it doesn't want to set a temporary environment. 我试图测试virtualenv但看起来它不想设置临时环境。

I believe that you should deal with these issues and avoid using 2 different Python environments. 我相信你应该处理这些问题并避免使用2种不同的Python环境。 But you could achieve this with pyenv . 但你可以用pyenv实现这一目标

Let's say that 3.7.0 is your system Python version. 假设3.7.0是您的系统Python版本。 First, install pyenv and a 3.7.3 environment: 首先,安装pyenv3.7.3环境:

$ pyenv update
$ pyenv install 3.7.3
$ pyenv shell 3.7.3

Then, install PyQt5 and the other requirements with pip . 然后,用pip安装PyQt5和其他要求。

Eventually, you will be able to switch to a every installed versions, manually or within your script. 最终,您将能够手动或在脚本中切换到每个已安装的版本。

pyenv also supports virtual environments. pyenv还支持虚拟环境。

Made it. 做好了。

In 3.7.0 script I add 在3.7.0脚本中我添加

import sys 
qt_bundle =['~long_path_to_appdata\\Python\\Python37-32\\lib\\site-packages\\'] # list in case I need to add more modules
sys.path+= qt_bundle

after that this statement 在此之后

from PyQt5 import QtCore, QtWidgets

does not throw any error 不会抛出任何错误

暂无
暂无

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

相关问题 从 Python 脚本运行 npm 脚本。 获得不一致的行为 - Running npm script from Python script. Getting inconsistent behavior Python:对脚本运行命令行应用程序。 在文件中发送参数 - Python: Running command line application to the script. Sending parameters in files 一台电脑有两个版本的python - Two versions of python in one computer python 中是否可以有两个运行相同脚本的独立 shell? - Is it possible to have two separate shells in python that are running the same script? 使用Python ssh然后运行bash脚本。 我需要在屏幕上显示正在运行的bash脚本的输出 - Using Python to ssh then run bash script. The output of the running bash script i need to display on the screen 在同一脚本中使用两个单独的python版本 - Use two separate versions of python in the same script AWS Lambda Python 脚本。 如何返回对象并保持 scipt 在后台运行? - AWS Lambda Python script. How do I return an object and keep the scipt running in the background? 在 Python 上运行 AppleScript:“语法错误:预期行尾,但发现脚本结束。” - Running AppleScript on Python : “Syntax Error: Expected end of line but found end of script.” 在 SQL Server 中运行 xp_cmdshell 以运行 python 脚本。 Xlwings 部分抛出“访问被拒绝”错误 - Running xp_cmdshell in SQL Server to run python script. Xlwings portion throws 'Access is denied' error Python命令行脚本。 有两种使用场景。 如何实现参数解析? - Python command line script. Two scenarios of using. How to implement arguments parsing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM