简体   繁体   English

无法导入已安装的软件包

[英]Can't import installed package

I'm having a bit of trouble getting my setup.py file to work correctly. 我有一些麻烦让我的setup.py文件正常工作。 I'm able to run the install command and everything appears to be working. 我能够运行install命令,并且一切似乎都可以正常工作。 I see all the appropriate files being copied to various locations and there aren't any error messages but when I actually try to import the package from the python command line I get errors saying it doesn't exist. 我看到所有适当的文件都被复制到了不同的位置,并且没有任何错误消息,但是当我实际尝试从python命令行导入包时,我收到错误消息,指出它不存在。

Python安装输出 Larger picture 大图

Can anyone suggest what I'm doing wrong here? 有人可以在这里暗示我在做什么错吗?

Make sure you cd out of the install directory, otherwise you'll get weird behaviour. 确保您从安装目录中退出cd,否则您将得到奇怪的行为。 Also, if you run 另外,如果您跑步

import sys
print sys.path

Make sure the module was installed to a location that is on your python path 确保将模块安装到python路径上的位置

Assuming that's all the files to compiled in the picture, here is why all you tries failed. 假设这是图片中要编译的所有文件,这就是您尝试全部失败的原因。

1) You do not have a file named passport.phaseI. 1)您没有名为passport.phaseI的文件。 Imports must be mapped to a file. 导入必须映射到文件。

2) Assuming you mean to import the Passport class in the passport/phase/passport file, you need to call it like: from passport.phase.passport import Passport 2)假设您打算在Passport / phase / passport文件中导入Passport类,则需要这样调用: from passport.phase.passport import Passport

3) See number 1. You do not have a file named passport, but you do have a dir. 3)参见编号1。您没有名为通行证的文件,但有目录。

I think the code from number two is going to help you the best. 我认为第二个代码将为您提供最好的帮助。

Edit: One more note: remember your __init__.py files in each folder. 编辑:另一个注意事项:请记住每个文件夹中的__init__.py文件。

Hope this helps! 希望这可以帮助!

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

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