Pipenv安装的git软件包不可导入

时间:2020-03-12 14:18:45

标签: python-3.x installation pipenv

我正在使用pipenv(版本2018.11.26,Python 3.6.0)安装我创建的软件包并将其推送到私有github存储库上。

该软件包包含一个setup.py文件,其内容如下:

import setuptools

setuptools.setup(
    name='testlib',
    version='0.0.1',
    desctiption='Hello py packaging',
    packages=setuptools.find_packages()
)

我将软件包安装在virtualenv中,

pipenv install  git+https://<token>@github.<private-repo>/<subdir>/testlib.git#egg=testlib
> Successfully installed testlib-0.0.1

并检查是否已正确安装

$ pip freeze | grep testlib
> testlib==0.0.1

但是,如果我尝试导入模块,则会得到ModuleNotFoundError

(.venv) pipenv_tests>python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import testlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'testlib'
>>>

有人可以帮助我理解为什么吗? 谢谢

1 个答案:

答案 0 :(得分:2)

我不好,文件夹结构不正确!

setup.py必须在包文件夹之外:

repo_folder
|_ setup.py
|_ testlib
|__ classa.py
|__ classb.py

setup.py(如问题中所述)在哪里

import setuptools

setuptools.setup(
    name='testlib',
    version='0.0.1',
    desctiption='Hello py packaging',
    packages=setuptools.find_packages()
)

现在,如果我导入该程序包,它将起作用!!!

(.venv) pipenv_tests>python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:06:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import testlib
>>> _