简体   繁体   中英

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
|_PyFinances
|  |_ __init__.py
|  |_ finances.py
|_ data
|_ test
|_ scripts
|_ docs
|_ README.rst
|_ LICENSE
|_ setup.py
|_ Makefile
|_ requirements.txt
|_ .venv

The Makefile has the contents

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

And the setup.py has the following contents

# -*- 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. I am working in a virtual environment and start by installing wheel with the following command when in the uppermost PyFinances directory.

pip3 install wheel

Then I install my package with the following command.

pip3 install .

The installer presents me with the message Successfully installed PyFinances-0.10 , which makes me think everything worked fine. 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 . Can anyone tell me what is wrong with my process for turning my own Python code into a local install?

After much investigating I found that I was using the wrong virtual environment, which prevented me from accessing my package. After changing to the correct.venv file it fixed the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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