简体   繁体   English

安装仅一个Python文件且没有setup.py的软件包

[英]Install a package that is only one Python file and has no setup.py

How can i install a python package that does not have a setup.py file to call. 我如何安装没有 setup.py文件的python软件包。 I want to install a package that it happens to be only a .py . 我想安装一个恰好只是.py的软件包。

Do i just save it as a .py and put it somewhere in the directory and then import it? 我是否只是将其另存为.py并将其放置在目录中的某个位置,然后将其导入?

For example the zipfile package and the ElementTree XML parser 例如zipfile包ElementTree XML解析器

PS: I have Python-3.x PS:我有Python-3.x

Edit: As said in the comments, these packages come with Python 3 so you should not install them manually (and certainly not the 2.7 versions). 编辑:如评论中所述,这些软件包是Python 3附带的,因此您不应该手动安装它们(当然不是2.7版本)。 I let my answer bellow for people wanting to install custom package. 对于希望安装自定义程序包的人,我让其回答如下。

On a python interpreter, if you run: 在python解释器上,如果运行:

>>> import sys
>>> sys.path

You will see a list of folder where your python executable search for module. 您将看到python可执行文件搜索模块的文件夹列表。 You can put your file either in the site-packages folder or the lib folder. 您可以将文件放在site-packages文件夹或lib文件夹中。

只需将文件放在PYTHONPATH中。

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

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