Questions tagged [python-packaging]
Packages are namespaces which contain multiple packages and modules themselves.
python-packaging
1,514
questions
3792
votes
14
answers
2.5m
views
What is __init__.py for?
What is __init__.py for in a Python source directory?
1794
votes
15
answers
658k
views
Relative imports for the billionth time
I've been here:
PEP 328 – Imports: Multi-Line and Absolute/Relative
Modules, Packages
Python packages: relative imports
Python relative import example code does not work
Relative imports in Python 2....
1613
votes
10
answers
1.2m
views
What is setup.py?
What is setup.py and how can it be configured or used?
1305
votes
34
answers
1.5m
views
How do I remove all packages installed by pip?
How do I uninstall all packages installed by pip from my currently activated virtual environment?
1273
votes
23
answers
3.0m
views
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)
435
votes
8
answers
474k
views
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 ...
408
votes
25
answers
306k
views
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 ...
227
votes
4
answers
97k
views
"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
106
votes
4
answers
40k
views
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
│ ...
100
votes
6
answers
99k
views
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 ...
79
votes
1
answer
58k
views
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 ...
75
votes
5
answers
158k
views
How to run a script using pyproject.toml settings and poetry?
I am using poetry to create .whl files. I have an FTP sever running on a remote host. I wrote a Python script (log_revision.py) which save in a database the git commit, few more parameters and in the ...
70
votes
4
answers
185k
views
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
│ └── ...
60
votes
5
answers
23k
views
Is requirements.txt still needed when using pyproject.toml?
Since mid 2022 it is now possible to get rid of setup.py, setup.cfg in favor of pyproject.toml. Editable installs work with recent versions of setuptools and pip and even the official packaging ...
59
votes
2
answers
11k
views
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, ...
57
votes
4
answers
29k
views
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 ...
50
votes
21
answers
557k
views
Message "error: Microsoft Visual C++ 14.0 or greater is required."
While downloading pip install allennlp==1.0.0 allennlp-models==1.0.0, I faced this problem:
[6 lines of output]
running bdist_wheel
running build
running build_py
...
42
votes
2
answers
22k
views
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 ...
39
votes
3
answers
23k
views
How to list dependencies for a python library without installing? [duplicate]
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, ...
38
votes
2
answers
24k
views
Is `setup.cfg` deprecated?
It's not completely clear to me, what is the status of setup.cfg. I am looking for solutions for my other question about PEP 508 environment markers, and I became totally confused.
To me it seems ...
35
votes
3
answers
11k
views
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]
...
34
votes
2
answers
27k
views
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
│ └── ...
34
votes
3
answers
15k
views
Is there a simple way to convert setup.py to pyproject.toml
We have multiple python projects, and are considering converting them to use pyproject.toml instead of setup.py.
Is there a simple way to automate this?
33
votes
1
answer
30k
views
Difference between 'Directory' and 'Python Package' in PyCharm
When to use Directory over Python Package? PS: I understand that I can import from latter but not former. If so, why not create everything as a Python Package?
Also, does PyCharm mark a location as ...
33
votes
3
answers
30k
views
python pip priority order with index-url and extra-index-url
I searched a bit but could not find a clear answer.
The goal is, to have two pip indexes, one is a private index, that will be a first priority. And one is the standard PyPI. The priority is there to ...
31
votes
3
answers
8k
views
Automating Python package release process
I've just started an open source Python project that I hope might be popular one day. At the moment to release a new version I have to do a few things.
Test all the things.
Edit mypackage.VERSION ...
30
votes
1
answer
21k
views
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 ...
29
votes
2
answers
10k
views
What's the difference between the [tool.poetry] and [project] tables in pyproject.toml? [closed]
Context
So, I'm trying to create a new Python package following this tutorial: https://packaging.python.org/en/latest/tutorials/packaging-projects/
As the tutorial says, in my pyproject.toml I should ...
28
votes
7
answers
18k
views
How to access python package metadata from within the python console?
If I have built a python package employing distutils.core, e.g. via
setup(
ext_package="foo",
author="me",
version="1.0",
description="foo package",
packages=["foo",],
)
where ...
27
votes
2
answers
6k
views
How to build a C extension in keeping with PEP 517, i.e. with pyproject.toml instead of setup.py?
I want to build a C extension for CPython. I could do it traditionally with a setup.py file. However, for the reasons mentioned in PEP 517, I would prefer a declarative approach using a pyproject.toml....
27
votes
2
answers
6k
views
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 (...
26
votes
1
answer
6k
views
single-sourcing package version for setup.cfg Python projects
For traditional Python projects with a setup.py, there are various ways of ensuring that the version string does not have to be repeated throughout the code base. See PyPA's guide on "Single-sourcing ...
25
votes
3
answers
12k
views
How to build and distribute a Python/Cython package that depends on third party libFoo.so
I've written a Python module that depends on some C extensions. Those C extensions depend in turn on several compiled C libraries. I'd like to be able to distribute this module bundled with all the ...
24
votes
5
answers
38k
views
How to accomplish relative import in Python
Consider:
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 ...
24
votes
1
answer
15k
views
Python commands to build distribution setup.py build vs python -m build
I'm learning about Python packaging, and according to this guide, the command to build a python distribution package seems to be python3 -m build.
But I aslo found that there is a command line ...
23
votes
2
answers
10k
views
Trying to read JSON file within a Python package
I am in the process of packaging up a python package that I'll refer to as MyPackage.
The package structure is:
MyPackage/
script.py
data.json
The data.json file comprises cached data that is ...
23
votes
1
answer
20k
views
What is 'extra' in pypi dependency?
In requires_dist section of a package's json response from pypi, it is given:
requires_dist : [
"bcrypt; extra == 'bcrypt'",
"argon2-cffi (>=16.1.0); extra == 'argon2'"
]
can anyone make ...
22
votes
10
answers
22k
views
module 'pip' has no attribute 'pep425tags'
When I am trying to install .whl with pip
it said:
... is not a supported wheel on this platform
to solve this problem, I searched the Internet and it said I can input this into repl
import pip; ...
21
votes
1
answer
27k
views
Pip install error missing 'libxml/xmlversion.h'
I need to install the python package xmlsec(https://pypi.python.org/pypi/xmlsec) and when I try running
pip install xmlsec
It gives me this error:
src\xmlsec\constants.c(266) : fatal error C1083: ...
19
votes
3
answers
6k
views
Python: How do I find which pip package a library belongs to?
I got a script transferred from someone else. And there is a module imported into the script. I'm wondering what is the best way to find out which pip package installed this library (other than search ...
19
votes
2
answers
4k
views
Prevent package from being installed on old Python versions
What can we put in a setup.py file to prevent pip from collecting and attempting to install a package when using an unsupported Python version?
For example magicstack is a project listed with the ...
19
votes
1
answer
14k
views
Pip pyproject.toml: Can optional dependency groups require other optional dependency groups?
I am using the latest version of pip, 23.01. I have a pyproject.toml file with dependencies and optional dependency groups (aka "extras"). To avoid redundancies and make managing optional ...
18
votes
2
answers
13k
views
Multilevel relative import
Multilevel relative import
I have following folder structure
top\
__init__.py
util\
__init__.py
utiltest.py
foo\
__init__.py
foo.py
bar\
__init__.py
...
18
votes
1
answer
3k
views
Anaconda/Python site-packages subfolders with tilde in name - what are they?
Today, I went to change the config of matplotlib. Searching matplotlibrc revealed I have two of them:
Looking at the site-packages folder, I found a lot of packages have a tilde in their name:
~...
18
votes
1
answer
12k
views
Specifying test dependencies in pyproject.toml and getting them installed with pip install -e
I have a Python project with a pyproject.toml similar to the one below. I use python build to generate an package I use to install in production environments. For development environments, I use pip ...
18
votes
1
answer
34k
views
How to build python project based on pyproject.toml
I would like to understand current state of Python build systems and requirements management.
Imagine, that I checked out sources of some project that is using poetry (or pipenv). And this project ...
18
votes
2
answers
11k
views
setup.py -- configuration for private / commercial projects
What can I put on our setup.py project configuration file to tell the developers that the project is a private/commercial application/library.
Currently I set:
setup(
name='MyProject',
...
18
votes
3
answers
5k
views
What is the best way to check if a PyPI package name is taken?
What is the best way to check if a PyPI package name is taken?
Several times now I have searched pypi for a package and received no results. Then I have taken the time to create a package with a name ...
16
votes
5
answers
61k
views
Import modules from subfolders
I have following arrangement of files:
python
|---- main.py
|---- files
|---- folder1
|---- a.py, a1.py, ...
|---- folder2
|---- b.py, b1.py, ...
I wanted to ...
16
votes
5
answers
19k
views
pip installing environment.yml as if it's a requirements.txt
I have an environment.yml file, but don't want to use Conda:
name: foo
channels:
- defaults
dependencies:
- matplotlib=2.2.2
Is it possible to have pip install the dependencies inside an ...