[英]Cannot import local package installed with `pip install -e .`
I have a package under development and also a few scripts that import this package.我有一个 package 正在开发中,还有一些脚本可以导入这个 package。 I am trying to install the package with developer mode using
pip install -e.
我正在尝试使用
pip install -e.
but then I cannot import it in my scripts.但后来我无法在我的脚本中导入它。 I have the following file structure where
singlepixel
is a package I am developing.我有以下文件结构,其中单像素是我正在开发的
singlepixel
。
├── setup.py
├── singlepixel
│ ├── acquisition.py
│ ├── metadata.py
│ └── __init__.py
├── scripts
│ ├── script1.py
│ └── script2.py
My __init__.py
has the following structure:我的
__init__.py
具有以下结构:
from .acquisition import init, setup, acquire, disconnect
from .metadata import MetaData, AcquisitionParameters
And my setup.py
is:我的
setup.py
是:
from setuptools import setup, find_packages
setup(
name='singlepixel',
version='0.0.1',
author='gbm',
package_dir={"": "singlepixel"},
packages=find_packages(where="singlepixel"))
From my understanding, I should be able to do a simple import statement in my script1.py
such as from singlepixel import *
, however it does not work and I get the following error instead:据我了解,我应该能够在我的
script1.py
中执行一个简单的导入语句,例如from singlepixel import *
,但是它不起作用,而是出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'singlepixel'
Moreover it seems that I am not able to import the package anywhere even though I am using an anaconda environment.此外,即使我使用的是 anaconda 环境,我似乎也无法在任何地方导入 package。 From my understanding, I should be able to import my package anywhere when using this environment just like any other package installed with
pip install
.据我了解,在使用此环境时,我应该能够在任何地方导入我的 package,就像安装了
pip install
的任何其他 package 一样。
You don't have packages inside singlepixel/
, that directory itself is a package.您在
singlepixel/
中没有包,该目录本身是 package。 So remove所以删除
package_dir={"": "singlepixel"},
and change和改变
packages=find_packages(where="singlepixel"))
to至
packages=find_packages())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.