简体   繁体   English

python模块存储在哪里?

[英]Where are python modules stored?

I'm new to this and wondering, where's all the code for the modules and packages and stuff that you can import located on my computer.我对此很陌生,想知道模块和包的所有代码以及您可以在我的计算机上导入的内容的所有代码。

Can anyone give me a short lesson and help me out?谁能给我一个简短的课程并帮助我?

Suppose you want to know the location of xyz module.假设您想知道xyz模块的位置。 You do this on the interpreter你在口译员上做这件事

>>> import xyx
>>> xyz.__file__

You'll get the location of the pyc file from where your module is being imported.您将从导入模块的位置获取pyc文件的位置。

You can also simply do你也可以简单地做

>>> xyz

to get the module name and the location of the module.获取模块名称模块的位置。

To know about all the possible locations from where the modules are imported, use sys.path :要了解导入模块的所有可能位置,请使用sys.path

>>> import sys
>>> sys.path

This will give you the list of the locations where Python searches for a module when you do import .这将为您提供在执行import时 Python 搜索模块的位置列表。

Hope that helps.希望有帮助。

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

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