0

我知道这个问题之前已经被问过,他们是关于这个主题的参考资料,但这些说明似乎都不起作用。我有一个名为 PyFinances 的包,其目录结构如下,我正在使用 BigSur OS V11.1 的 Macintosh 计算机

PyFinances
|_PyFinances
|  |_ __init__.py
|  |_ finances.py
|_ data
|_ test
|_ scripts
|_ docs
|_ README.rst
|_ LICENSE
|_ setup.py
|_ Makefile
|_ requirements.txt
|_ .venv

Makefile内容

init:
        pip3 install -r requirements.txt
test:
        pytest -s test

并且setup.py有以下内容

# -*- coding: utf-8 -*-

# Learn more: https://github.com/kennethreitz/setup.py

from setuptools import setup, find_packages


with open('README.rst') as f:
    readme = f.read()

with open('LICENSE') as f:
    license = f.read()

setup(
    name='PyFinances',
    version='0.1.0',
    description='develops a statistical estimate for the value of checking and savings account',
    long_description=readme,
    author='Jonathan A. Webb',
    author_email='webbja123@gmail.com',
    license=license,
    packages=find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "Programming Languate :: Python :: 3.9", 
        "Operating System :: MacOS",
    ],
    zip_safe=False,
)

我正在尝试将自己的代码作为包安装在本地系统上,而不将其上传到 PyPi。我在虚拟环境中工作,并在最上面的PyFinances目录中使用以下命令安装 wheel。

pip3 install wheel

然后我使用以下命令安装我的包。

pip3 install .

安装程序向我显示消息Successfully installed PyFinances-0.10,这让我认为一切正常。但是,如果我 cd 到一个完全不同的目录并打开 Python 命令行界面并键入import PyFinances,或者尝试使用使用相同命令的文件,我会得到一个ModuleNotFoundError. 谁能告诉我将自己的 Python 代码转换为本地安装的过程有什么问题?

4

1 回答 1

1

经过大量调查,我发现我使用了错误的虚拟环境,这阻止了我访问我的包。更改为正确的 .venv 文件后,它解决了问题。

于 2021-02-08T13:13:49.063 回答