简体   繁体   English

仅使用虚拟环境文件夹运行python脚本

[英]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.

相关问题 使用yaml文件在虚拟环境中运行本地python脚本 - run local python script inside virtual environment using yaml file 如何在 Mac 上使用 anaconda 虚拟环境运行 python 脚本 - How to run a python script using an anaconda virtual environment on mac 在不激活虚拟环境的情况下运行Python脚本 - Run Python script without activating virtual environment 使用optirun在虚拟环境中运行python脚本 - Run python scripts in virtual environment using optirun 如何在没有cmd的虚拟环境中使用python运行python脚本 - How to run python script with python from virtual environment without cmd 使用 EC2 实例上的虚拟环境从浏览器运行 Python 脚本 - Run Python script from browser using virtual environment on EC2 instance C# 从虚拟环境运行 python 脚本 - C# run python script from virtual environment 如何在虚拟环境中运行 shell 执行的 python 脚本 - How to run shell-exectued python script in a virtual environment 激活虚拟环境,然后使用 VBA 和 Excel 运行 python 脚本 - Active a virtual environment then run a python script with VBA & Excel 如何仅使用 virtualenv 引导脚本在虚拟环境中安装 python 包? - How to install python packages in virtual environment only with virtualenv bootstrap script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM