简体   繁体   English

在Windows中调用python脚本时自动使用virtualenv

[英]Automatically use virtualenv when calling a python script in Windows

I'm a beginner and I can't find a concrete answer on how to do what I'm trying to accomplish: 我是一个初学者,我无法找到有关如何做自己想完成的事情的具体答案:

Basically I call my script "traffic.py" from a Java app, so I need my script to automatically use the virtualenv I created for it. 基本上,我从Java应用程序中将脚本称为“ traffic.py”,因此需要脚本来自动使用为其创建的virtualenv。 I read that if you put your script in the ./bin/ folder from your virtualenv, it automatically uses its interpreter. 我了解到,如果您将脚本从virtualenv放在./bin/文件夹中,它将自动使用其解释器。 This works on Ubuntu, but whenever I try the same thing on Windows, I get an error message telling me "ModuleNotFoundError: No module named 'psutil'", indicating that the virtualenv has not been activated. 这在Ubuntu上有效,但是每当我在Windows上尝试相同的操作时,我都会收到一条错误消息,告诉我“ ModuleNotFoundError:没有名为'psutil'的模块”,表明virtualenv尚未激活。

I'm sure the answer is really simple, and greatly appreciate you taking your time to read my post! 我相信答案确实很简单,非常感谢您抽出宝贵的时间阅读我的帖子!

You can call the python script with PYTHONHOME set to the virtualenv directory. 您可以将PYTHONHOME设置为virtualenv目录来调用python脚本。

https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME

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

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