简体   繁体   English

即使我有python setup.py开发它也无法按库名导入

[英]Can't import by library name, even though I have python setup.py develop it

I am running into a very strange python import problem. 我遇到了一个非常奇怪的python导入问题。 I wrote my own repo, and used a setup.py script to setup the import path, script below: 我编写了自己的存储库,并使用setup.py脚本设置了导入路径,脚本如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from __future__ import unicode_literals

from setuptools import setup, find_packages

__author__ = 'Shaun Rong'
__version__ = '0.1'
__maintainer__ = 'Shaun Rong'
__email__ = 'rongzq08@gmail.com'

if __name__ == "__main__":
    setup(name='Quantomic',
          version=__version__,
          author="Ziqin (Shaun) Rong, Wenxuan Huang",
          author_email="rongzq08@mit.edu key01027@mit.edu",
          license="MIT License",
          packages=find_packages(),
          zip_safe=False)

I used python setup.py develop to run the codes. 我使用python setup.py develop来运行代码。 Now, however, I can't import the whole library by name Quantomic , any codes like 但是,现在,我无法通过名称Quantomic导入整个库,例如

import Quantomic

or 要么

from Quantomic import settings

will raise the error: ImportError: No module named Quantomic 会引发错误: ImportError: No module named Quantomic

I do have a __init__.py under the library root, and I checked sys.path , /Users/shaunrong/Documents/projects/Quantomic is in the path. 我确实在库根目录下有一个__init__.py ,我检查了sys.path/Users/shaunrong/Documents/projects/Quantomic在路径中。

I do, however, can import using relative paths in any codes inside Quantomic, using like 但是,我可以在Quantomic中的任何代码中使用相对路径导入,例如

import settings

will work OK. 可以正常工作。

Can anyone tell me what is going on? 谁能告诉我发生了什么事? I am happy to provide more information upon request! 我很乐意应要求提供更多信息!

UPDATE 更新

File/Folder structure looks like: 文件/文件夹结构如下:

/Quantomic
    __init__.py
    settings.py
    /data
        __init__.py
        price.py 

Your setup.py file is in the wrong directory. 您的setup.py文件位于错误的目录中。 Here is your folder structure 这是您的文件夹结构

/Quantomic
    setup.py
    __init__.py
    settings.py
    /data
        __init__.py
        price.py 

It should look like this 它应该看起来像这样

/Quantomic (can be named anything)
    setup.py
    /Quantomic
        __init__.py
        settings.py
        /data
            __init__.py
            price.py 

When you last ran setup.py , it likely installed a data library into your python installation. 上次运行setup.py ,它可能已在python安装中安装了一个data Or, because you used develop , it added the path above data to the pythonpath using a pth file in your python libs folder. 或者,因为你使用的develop ,它增加了上面的路径data使用的PYTHONPATH pth在你的Python库文件夹文件。

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

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