Questions tagged [python-packaging]

Packages are namespaces which contain multiple packages and modules themselves.

A package is a directory containing a special file called __init__.py (which indicated that the directory contains a python package) and sub-packages and modules. The package name is determined by the name of the directory.

1369 questions
3611
votes
14 answers

What is __init__.py for?

What is __init__.py for in a Python source directory?
Mat
  • 82,161
  • 34
  • 89
  • 109
1668
votes
12 answers

Relative imports for the billionth time

I've been here: http://www.python.org/dev/peps/pep-0328/ http://docs.python.org/2/tutorial/modules.html#packages Python packages: relative imports python relative import example code does not work Relative imports in python 2.5 Relative imports in…
user1881400
1539
votes
10 answers

What is setup.py?

What is setup.py and how can it be configured or used?
Software Enthusiastic
  • 25,147
  • 16
  • 58
  • 68
1211
votes
23 answers

How do I import other Python files?

How do I import files in Python? I want to import: a file (e.g. file.py) a folder a file dynamically at runtime, based on user input one specific part of a file (e.g. a single function)
Tamer
  • 12,137
  • 3
  • 16
  • 4
1187
votes
34 answers

How do I remove all packages installed by pip?

How do I uninstall all packages installed by pip from my currently activated virtual environment?
blueberryfields
  • 45,910
  • 28
  • 89
  • 168
428
votes
7 answers

How to write a Python module/package?

I've been making Python scripts for simple tasks at work and never really bothered packaging them for others to use. Now I have been assigned to make a Python wrapper for a REST API. I have absolutely no idea on how to start and I need help. What I…
yowmamasita
  • 4,810
  • 3
  • 17
  • 17
384
votes
25 answers

Standard way to embed version into Python package?

Is there a standard way to associate version string with a Python package in such way that I could do the following? import foo print(foo.version) I would imagine there's some way to retrieve that data without any extra hardcoding, since…
Dimitri Tcaciuc
  • 5,053
  • 5
  • 20
  • 22
226
votes
4 answers

"pip install --editable ./" vs "python setup.py develop"

Is there any significant difference between pip install -e /path/to/mypackage and the setuptools variant? python /path/to/mypackage/setup.py develop
PeterE
  • 5,715
  • 5
  • 29
  • 51
88
votes
6 answers

How do I list the files inside a python wheel?

I'm poking around the various options to setup.py for including non-python files, and they're somewhat less than intuitive. I'd like to be able to check the package generated by bdist_wheel to see what's actually in it--not so much to make sure that…
Andrew
  • 4,058
  • 4
  • 25
  • 37
87
votes
3 answers

Using pytest with a src layer

pytest recommends including an additional directory to separate the source code within a project: my_package ├── src # <-- no __init__.py on this layer │   └── my_package │   ├── __init__.py │   └── util_module │   ├──…
Arne
  • 17,706
  • 5
  • 83
  • 99
65
votes
1 answer

How to write a minimally working pyproject.toml file that can install packages?

Pip supports the pyproject.toml file but so far all practical usage of the new schema requires a 3rd party tool that auto-generates these files (e.g., poetry and pip). Unlike setup.py which is already human-writeable, pyproject.toml is not…
Keto
  • 1,470
  • 1
  • 12
  • 25
61
votes
3 answers

How to import a module from a different folder?

I have a project which I want to structure like this: myproject ├── api │ ├── __init__.py │ └── api.py ├── backend │ ├── __init__.py │ └── backend.py ├── models │ ├── __init__.py │ └── some_model.py └── __init__.py Now, I want to import…
Gasp0de
  • 1,199
  • 2
  • 12
  • 30
60
votes
2 answers

How to easily distribute Python software that has Python module dependencies? Frustrations in Python package installation on Unix

My goal is to distribute a Python package that has several other widely used Python packages as dependencies. My package depends on well written, Pypi-indexed packages like pandas, scipy and numpy, and specifies in the setup.py that certain…
yyk
  • 681
  • 1
  • 5
  • 8
56
votes
4 answers

Python: Multiple packages in one repository or one package per repository?

I have a big Python 3.7+ project and I am currently in the process of splitting it into multiple packages that can be installed separately. My initial thought was to have a single Git repository with multiple packages, each with its own setup.py.…
AstrOne
  • 3,569
  • 7
  • 32
  • 54
41
votes
2 answers

How do I use a relative path in a Python module when the CWD has changed?

I have a Python module which uses some resources in a subdirectory of the module directory. After searching around on stack overflow and finding related answers, I managed to direct the module to the resources by using something like import…
jvkersch
  • 575
  • 1
  • 4
  • 9
1
2 3
91 92