简体   繁体   English

如何打包和导出您的所有项目?

[英]How to package and export all of your project?

I am a beginner at programming, and I have completed a project based on python 3.8 which uses several libraries, some not included in the default python environment.我是一个编程初学者,我已经完成了一个基于 python 3.8 的项目,它使用了几个库,其中一些库不包含在默认的 python 环境中。

When I send the simple file with the .py code and the pictures (icons etc) to my friend, the code does not run, as the libraries are not found.当我将带有 .py 代码和图片(图标等)的简单文件发送给我的朋友时,代码不会运行,因为找不到库。 Same if I run it with a different version of python...如果我用不同版本的python运行它也是一样的......

I was wondering how to properly pack all my libraries and dependencies in a single file to export?我想知道如何正确地将我的所有库和依赖项打包到一个文件中以进行导出? What is the structure to follow for someone to be able to run the code properly with the required libraries all included?为了使某人能够正确运行代码并包含所有必需的库,应遵循什么结构?

(working on visual studio 2019) (在视觉工作室 2019 上工作)

Thank you for your time感谢您的时间

The common practice for specifying your python script's dependencies is to redirect the output of the $ pip freeze command to a file named requirements.txt .指定 python 脚本依赖项的常见做法是将$ pip freeze命令的输出重定向到名为requirements.txt的文件。 That is of course done with the redirect operator as follows: $ pip freeze > requirements.txt .这当然是使用重定向运算符完成的,如下所示: $ pip freeze > requirements.txt Your friend can then $ pip install -r requirements.txt from the archive you provided them to get the required libraries.然后,您的朋友可以$ pip install -r requirements.txt从您提供给他们的存档中获取所需的库。 Refer to $ pip help install and the pip documentation for more details.有关详细信息,请参阅$ pip help installpip 文档

EDIT: $ pip freeze apparently captures way more than is necessary, you can simply write the names of libraries used in the requirements file by hand, eg编辑: $ pip freeze显然捕获的方式超出了必要的范围,您可以简单地手动编写需求文件中使用的库的名称,例如

qrcode
pyperclip
pandas
numpy
<any other dependency>

with each one on seperate lines and with a version specified after an equal sign if needed.每一个都在单独的行上,如果需要,在等号后指定一个版本。

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

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