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.

724 questions
2757
votes
12 answers

What is __init__.py for?

What is __init__.py for in a Python source directory?
Mat
  • 67,636
  • 33
  • 83
  • 106
1223
votes
10 answers

What is setup.py?

Can anyone please explain what setup.py is and how it can be configured or used?
Software Enthusiastic
  • 21,163
  • 15
  • 55
  • 66
951
votes
21 answers

How to import other Python files?

How do I import other files in Python? How exactly can I import a specific python file like import file.py? How can I import a folder instead of a specific file? I want to load a Python file dynamically at runtime, based on user input. I want to…
Tamer
  • 9,529
  • 3
  • 14
  • 4
205
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,101
  • 4
  • 21
  • 46
56
votes
4 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
  • 3,174
  • 4
  • 18
  • 32
39
votes
2 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
  • 10,476
  • 3
  • 48
  • 66
36
votes
2 answers

How to import a module from a different folder?

I have a project which I want to structure like this: myproject __init__.py api __init__.py api.py backend __init__.py backend.py models __init__.py some_model.py Now, I want to import the module some_model.py in…
Gasp0de
  • 719
  • 1
  • 7
  • 21
36
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
  • 525
  • 1
  • 4
  • 9
29
votes
1 answer

Relative imports in Python

Hey all -- I am pulling my hair out with relative imports in Python. I've read the documentation 30 times and numerous posts here on SO and other forums -- still doesn't seem to work. My directory structure currently looks like this src/ …
apexdodge
  • 5,699
  • 3
  • 22
  • 32
26
votes
3 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
  • 2,831
  • 3
  • 25
  • 46
24
votes
6 answers

How to accomplish relative import in python

stuff/ __init__.py mylib.py Foo/ __init__.py main.py foo/ __init__.py script.py script.py wants to import mylib.py This is just an example, but really I just want to do a relative import…
random
  • 553
  • 1
  • 4
  • 9
24
votes
3 answers

How to list dependencies for a python library without installing?

Is there a way to get a list of dependencies for a given python package without installing it first? I can currently get a list of requirements, but it requires installing the packages. For example, I can use pip to show basic requirements info,…
Brendan Abel
  • 28,703
  • 11
  • 72
  • 95
24
votes
2 answers

Python setuptools/distutils custom build for the `extra` package with Makefile

Preamble: Python setuptools are used for the package distribution. I have a Python package (let us call it my_package), that has several extra_require packages to it. Everything works just find (installation and build of the package, as well as…
22
votes
2 answers

Right way to set python package with sub-packages

I am trying to set a package with sub-packages in python. Here is the tree structure that I have at the moment: myPackage ├── __init__.py ├── mySubPackage1 │   ├── foo2.py │   ├── foo.py │   └── __init__.py ├── mySubPackage2 │   ├── bar2.py │   ├──…
Dror
  • 9,918
  • 17
  • 70
  • 137
21
votes
2 answers

How to build a source distribution without using setup.py file?

With the following package structure . ├── my_package │ └── __init__.py ├── setup.cfg └── setup.py Contents of setup.py from setuptools import setup setup() Contents of setup.cfg [metadata] name = my_package version = 0.1 [options] packages =…
platypus
  • 369
  • 1
  • 8
1
2 3
48 49