【问题标题】:Pipenv installed git package not importablePipenv 安装的 git 包不可导入
【发布时间】:2020-03-12 14:18:45
【问题描述】:

我正在使用 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()
)

我将包安装在一个虚拟环境中

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'
>>>

谁能帮我理解为什么? 谢谢

【问题讨论】:

    标签: python-3.x installation pipenv


    【解决方案1】:

    我的错,文件夹结构错了!

    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
    >>> _
    

    【讨论】:

      猜你喜欢
      • 2019-03-15
      • 1970-01-01
      • 2019-01-02
      • 2018-03-21
      • 1970-01-01
      • 2021-07-14
      • 2020-09-26
      • 2023-03-28
      相关资源
      最近更新 更多