简体   繁体   English

我在哪里放置或如何安装我自己的 Python 模块

[英]Where do I place or how do I install my own Python module

Sorry for the super-simple question, it's just that I haven't found a proper answer here (that worked for me).很抱歉这个超级简单的问题,只是我在这里没有找到正确的答案(对我有用)。

I've just wrote some demo Python code, a Python module (logically speaking) to be exact, and I want to import this and use it.我刚刚写了一些演示 Python 代码,准确地说是一个 Python 模块(从逻辑上讲),我想导入并使用它。

Where should I place my module_x.py file?我应该在哪里放置我的module_x.py文件? (I'm running on Windows ) (我在Windows 上运行)

I've checked that all the module .py files are placed under ..\\Python27\\Lib directory, but placing my file there doesn't work for me – when I try to run import module_x I get this error message:我已经检查过所有模块.py文件都放在..\\Python27\\Lib目录下,但是将我的文件放在那里对我不起作用 - 当我尝试运行import module_x我收到以下错误消息:

ImportError: No module named module_x

The simplest thing is to put it in the same folder as the script that uses it.最简单的方法是将它与使用它的脚本放在同一个文件夹中。

If even this does not work, check to see if Windows has snuck in a file extension such ".txt" that isn't visible in the way you are viewing the file name.如果这也不起作用,请检查 Windows 是否隐藏了文件扩展名,例如在您查看文件名的方式中不可见的“.txt”。

As you have time, please read how to deal with modules from a manual or book to learn to do it the right way.如果您有时间,请阅读手册或书籍中的如何处理模块,以学习以正确的方式进行处理。

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

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