Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create python development environment (virtualenv) using setup.py

I am working on a python project.

I have already created my setup.py file.

Is there a way to make use of setup.py file install_requires section so as to create my virtualenv, or do I have to explicitly create a requirements.txt file and proceed with

  • virtualenv -p python3 venv
  • pip install -r requirements.txt
like image 960
pkaramol Avatar asked Jul 24 '26 12:07

pkaramol


1 Answers

setup.py installs the package in whichever environment is active. If you want to install it in a virtualenv, then you need to activate it first. Otherwise it will install globally.

You can continue using requirements.txt but let setup.py handle the installation. You can then read the file and set the list of dependencies for install_requires section.

from setuptools import setup, find_packages

with open('requirements.txt') as f:
    requirements = f.readlines()

setup(
    name='myawesomepackage',
    version='0.1',
    packages=find_packages(),
    url='https://example.com',
    author='abdusco',
    description='',
    install_requires=requirements,
    entry_points=dict(console_scripts=[
        'myawesomeapp=app:main'
    ])
)

Here's requirements.txt

certifi==2019.3.9
chardet==3.0.4
Click==7.0
idna==2.8
requests==2.22.0
urllib3==1.25.3
like image 123
abdusco Avatar answered Jul 27 '26 08:07

abdusco