[英]Run python script using only the virtual environment folder
Let's stay I use pipenv
to create a virtual environment. 留下来,我使用
pipenv
创建虚拟环境。 In setting it up, specify the python version in the Pipfile, and also have the environment variable PIPENV_VENV_IN_PROJECT
set up so that the .venv
folder is created in the project folder. 进行设置时,请在Pipfile中指定python版本,并设置环境变量
PIPENV_VENV_IN_PROJECT
,以便在项目文件夹中创建.venv
文件夹。
Inside the .venv
folder, I find that it has all the packages I had specified in the pipfile, and also even the python executable of the version I specified. 在
.venv
文件夹中,我发现它具有我在pipfile中指定的所有软件包,甚至还有我指定的版本的python可执行文件。
If I copied my script and this .venv
folder to another machine but which does not have Python installed, how do I go about running my script/s using just the .venv
folder ? 如果我将脚本和此
.venv
文件夹复制到另一台未安装Python的计算机上, 那么如何仅使用.venv
文件夹运行脚本 ? There's a Python executable in there, but I'm trying to figure out how to get all the lib folders correctly as well. 那里有一个Python可执行文件,但我试图弄清楚如何正确获取所有lib文件夹。
Is this even possible? 这有可能吗? I know that alternative methods exist (such as pre-compiling the code using Cython/CXFreeze/etc .) but I was wondering about using just the virtual environment folder.
我知道存在其他方法(例如使用Cython / CXFreeze / etc进行代码预编译 ),但是我想知道仅使用虚拟环境文件夹。
That is not the purpose of Python virtualenv. 那不是Python virtualenv的目的。 You have to regenerate the virtualenv when you move your script.
移动脚本时,必须重新生成virtualenv。 The virtualenv can be different in every machine, depending of the OS, etc. For that exists the Requeriments.txt and that's why virtualenv's directory always appears in .gitignore files.
每台计算机上的virtualenv可能不同,具体取决于操作系统等。为此,存在Requeriments.txt,这就是为什么virtualenv的目录始终显示在.gitignore文件中的原因。 However, once you have generated the virtualenv, you must use the python executable located in the virtualenv directory, as follows (assuming you are using unix):
但是,一旦生成了virtualenv,则必须使用位于virtualenv目录中的python可执行文件,如下所示(假设您使用的是Unix):
venv/bin/python script.py
Or, using the activate script: 或者,使用激活脚本:
venv/bin/activate
python script.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.