简体   繁体   English

如何在不将其上传到 PyPi 的情况下在本地安装 Python package

[英]How do I install a Python package locally without uploading it to PyPi

I know this question has been asked before and their are references on this topic, but none of the instructions seem to work.我知道这个问题之前已经被问过,他们是关于这个主题的参考资料,但这些说明似乎都不起作用。 I have a package titled PyFinances with the following directory structure and I am working on a Macintosh computer with the BigSur OS V11.1我有一个名为 PyFinances 的 package 具有以下目录结构,我正在使用 BigSur OS V11.1 的 Macintosh 计算机

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

The Makefile has the contents Makefile有内容

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

And the setup.py has the following contents并且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,
)

I am trying to install my own code as a package on my system locally without uploading it to PyPi.我正在尝试在本地系统上将自己的代码安装为 package 而不将其上传到 PyPi。 I am working in a virtual environment and start by installing wheel with the following command when in the uppermost PyFinances directory.我在虚拟环境中工作,首先在最上面的PyFinances目录中使用以下命令安装 wheel。

pip3 install wheel

Then I install my package with the following command.然后我使用以下命令安装我的 package。

pip3 install .

The installer presents me with the message Successfully installed PyFinances-0.10 , which makes me think everything worked fine.安装程序向我显示Successfully installed PyFinances-0.10的消息,这让我认为一切正常。 However, if I cd to a totally different directory and open the Python command line interface and type import PyFinances , or try to use a file that uses the same command, I get a ModuleNotFoundError .但是,如果我 cd 到一个完全不同的目录并打开 Python 命令行界面并键入import PyFinances ,或者尝试使用使用相同命令的文件,我会得到一个ModuleNotFoundError Can anyone tell me what is wrong with my process for turning my own Python code into a local install?谁能告诉我将自己的 Python 代码转换为本地安装的过程有什么问题?

After much investigating I found that I was using the wrong virtual environment, which prevented me from accessing my package.经过大量调查后,我发现我使用了错误的虚拟环境,这使我无法访问我的 package。 After changing to the correct.venv file it fixed the problem.更改为正确的.venv 文件后,它解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM