[英]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:
首先,安装pyenv和3.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.