[英]Python3 cannot find module installed by pip3 even though it is deffintley installed
I have a folder structure我有一个文件夹结构
root
|-setup.py
|-src
| |-BDDexample
| |-ExampleSystem.py (contains a class called ExampleSystem)
| |-__init__.py (empty file)
|
|-tests
|-cucumber
|-features
|-steps
|-EnableSystemStepImpl.py
My setup.py
file is:我的
setup.py
文件是:
#!/usr/local/bin/python3.6
from setuptools import setup, find_packages
setup(
name="BDDexample",
version="0.2",
packages=find_packages()
)
I then installed this using pip3 install .
然后我使用
pip3 install .
. . I also tried
python3 setup.py bdist_wheel
followed by pip3 install dist/BDDexample-0.2-py3-none-any.whl
.我也试过
python3 setup.py bdist_wheel
然后是pip3 install dist/BDDexample-0.2-py3-none-any.whl
。
It finds the module BDDexample, and I can test this by typing pip3 list
, which shows the module.它找到模块 BDDexample,我可以通过键入
pip3 list
来测试它,它显示了模块。
However, in EnableSystemStepImpl.py
I have the line:但是,在
EnableSystemStepImpl.py
有一行:
from BDDexample.ExampleSystem import ExampleSystem
And I get the error:我得到错误:
ModuleNotFoundError: No module named 'BDDexample'
When I try to run this file.当我尝试运行此文件时。
Why is this happening!为什么会这样! It is installed, so why can it not find it.
已经安装了,为什么找不到。 I know there are loads of python import questions but it seems like I am doing everything right.
我知道有很多 python 导入问题,但似乎我做的一切都是正确的。
The file BDDexample.ExampleSystem is not getting extracted from ExampleSystem because it might not be in a direct accessible path for the pc to extract.文件 BDDexample.ExampleSystem 没有从 ExampleSystem 中提取,因为它可能不在 PC 提取的直接可访问路径中。 Please check if it is in your c drive etc...
请检查它是否在您的c盘等中...
I've found the answer, it's because I shouldn't have had the src
folder.我找到了答案,因为我不应该有
src
文件夹。 I've changed my directory structure to:我已将目录结构更改为:
root
|-setup.py
|-BDDexample
| |-ExampleSystem.py (contains a class called ExampleSystem)
| |-__init__.py (empty file)
|
|-tests
|-cucumber
|-features
|-steps
|-EnableSystemStepImpl.py
And it now works.现在它可以工作了。
I assume find_packages
couldn't find the BDDexample
module because it was inside another folder.我假设
find_packages
找不到BDDexample
模块,因为它在另一个文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.