python-packaging | Tutorial on how to structure Python packages | Build Tool library
kandi X-RAY | python-packaging Summary
kandi X-RAY | python-packaging Summary
Tutorial on how to structure Python packages
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Return joke .
- Return the README . rst file .
- Runs the main function
python-packaging Key Features
python-packaging Examples and Code Snippets
Community Discussions
Trending Discussions on python-packaging
QUESTION
I am writing a python package which is dependent on a number of large data files. These files are not included with the package. Instead, users are required to have these files on disk already (with an arbitrary path). What is the best way to make my package aware of the location of these files?
I have been reading about setup.py
and setup.cfg
but I am still not sure how to to this. It seems to me that a user-editable option in setup.cfg
would be a good way to go but I don't know if it is, if it can be done at all, or how I would do it if so...
I did see this almost identical question, Python Packaging: Ask user for variable values when (pip) installing, which focuses on user input during pip (which is discouraged in the comments). If that actually would be a good solution, I'm interested in how to do that too.
In my private development of the package, I have used module constants, as in
...ANSWER
Answered 2021-Jun-01 at 18:19This sounds like runtime configuration. It's none of the business of setup.py
, which is concerned with installing your package.
For app configuration, it would be common to specify this resource location by command-line argument, environment variable, or configuration file. You will usually want to either hard-code some sensible default path in case the user does not specify any configuration, or raise an exception in case of resources not existing / not found.
Example for environment var:
QUESTION
I have developed a Python package. My structure is the following :
...ANSWER
Answered 2021-May-26 at 13:52User configuration should usually be kept in the os-specific locations for application configs. The usual way to handle it as a package author is to
- write a default config file and put it into the package, e.g. at
src/my_package/default.ini
- this is better than writing the config as code, as yourmain.py
probably does, because you can re-use your parsing step, can copy the default config to get a valid user config, and just have to maintain a single file type - copy the default config into a user-specific directory, use
appdirs
to find out which one is correct on each os- you can either ask your users if it's ok to create a new config at e.g.
/home/user/.configs/my_app
and do it after confirmation, or just do it and tell them where to find it in case they want to customize something
- you can either ask your users if it's ok to create a new config at e.g.
- on application start, parse the default config first, then parse the user config and overwrite differing settings
- if you also allow configuration via environment variables, those will be parsed afterwards and should overwrite both default- and user-config
Just to have a starting point, my config-parsing usually looks somewhat like this:
config.py, somewhere in your package
QUESTION
I'm using Serverless v2.23.0 to deploy a bunch of endpoints to AWS Lambda functions. The Lambda functions run python 3.8. I want to automatically install a dependency upon deploy to AWS Lambda.
For example, I want the package pycurl
installed automatically. I am following the tutorial at https://www.serverless.com/blog/serverless-python-packaging
I added a requirements.txt
file which just has the line:
ANSWER
Answered 2021-Mar-09 at 13:46The libcurl-devel
& openssl-devel
packages are missing, use one of the lambci/lambda Docker images to build and make sure all the dependencies are installed.
Change your serverless.yml
to:
QUESTION
I would like to make a relocatable environment. So I need to use relative paths in the package installations. For this I just create a Conda Environment like this:
...ANSWER
Answered 2018-Nov-29 at 18:08I think that relocatable environments depend on the installed packages. They should be implemented with relative paths and avoiding hardcoded paths. All the paths that are used in the source code of the package should be inside the own package. So if you install well done package you won´t have any problem to relocate the environment in other folder or computer.
As you will need to add all the folders inside the package you will need to modify the arguments of the setup
. Add these two parameters in order to add folders to the final package. If you don´t do this the folders won´t copied to the site-packages
folder within the environment (the final destination when you install the package with pip
):
QUESTION
I spent significant time, finding solution to this one problem :
My setup.py is as follow :
...ANSWER
Answered 2020-May-05 at 16:51As the links above do not mentionned, we need to this extra line in setup.py :
QUESTION
I'd like to make a cli tool and found this as a reference: https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html
So I created a directory with the following structure
...ANSWER
Answered 2020-Apr-12 at 09:45The guide you are following is 5 years old and a little vague. You could setup your cli-tool like so:
QUESTION
I'm trying to build a python module, and install a script as part of the installation of the package.
i.e. I have a script foo
, and after the user installs the package, they should be able to run foo
on the command line.
In the docs, it says:
When we install the package, setuptools will copy the script to our PATH and make it available for general use.
Is it possible to find which folder the setup is supposed to install the script?
I have a setup.py that looks like this:
...ANSWER
Answered 2020-Apr-04 at 18:50Python's doc also says:
The Distutils install command is designed to make installing module distributions to an alternate location simple and painless. The basic idea is that you supply a base directory for the installation, and the install command picks a set of directories (called an installation scheme) under this base directory in which to install files. The details differ across platforms, so read whichever of the following sections applies to you.
Note that the various alternate installation schemes are mutually exclusive: you can pass --user, or --home, or --prefix and --exec-prefix, or --install-base and --install-platbase, but you can’t mix from these groups.
See it here
QUESTION
AWS Newbie here
I have to host my python scripts via gitlab CI as a lambda and trigger it by cloudwatch on AWS.
I am following the following tutorials:
- https://docs.gitlab.com/ee/user/project/clusters/serverless/aws.html
- https://serverless.com/blog/serverless-python-packaging/
From the first tutorial, I am taking just the .gitlab-ci.yml
file and adding it to the tutorial shown in the second tutorial (but instead of python 3.6, I am choosing 3.7 as the runtime)
I have the following serverless.yml
file
ANSWER
Answered 2020-Mar-27 at 12:43It seems like you missed step about adding serverless-python-requirements
plugin to serverless.yml
.
Try adding it as mentioned blog:
QUESTION
I have been stuck here for too long. I am trying to deploy a microservice that uses tensorflow. There is a single file by the name of handler.py
which has the simple code below:
ANSWER
Answered 2018-May-25 at 09:49As you've mentioned from the error you received it looks like your zipped package is too large. You received that other error because you have a module requirement in your script to use tensorflow.
Keep in mind the AWS Lambda Limits has a 50MB deployment package size limit. The Tensorflow package by itself is close to 50MB, so adding the Numpy package will take it well over the limit.
Have a look at this blog which does some investigation into the package limit sizing in AWS Lambda
https://hackernoon.com/exploring-the-aws-lambda-deployment-limits-9a8384b0bec3
QUESTION
I am packaging a python project and look for the "right" way to specify dpendencies on external files. I am aware of multiple ways to specify dpendencies, but I would like to know how these ways work practically, how they differ, and at which specific time points they are taking effect, respectively.
Known ways to specify dependencies (see here)
- We could specify the dependency in the
install_requires
argument ofsetuptools.setup
- We could use
requirements.txt
- We could use
setup.cfg
My main questions
- What are advantages and disadvantages of the different methods?
- When and in which order are the information in the respective files read? Would e.g. pip first execute
setup.py
and then check therequirements.txt
afterwards? - What happens if I specify a requirement only in one of the ways given above? What happens, if I speciefy different requirements with different ways?
Motivating example
I need to create a package that uses cython
and numpy
. As can be seen e.g. here, cython
(and similarly numpy
, must be imported before setuptools.setup
is called. Hence, setup.py
would raise an ImportError
if the library is not available. How would I make the requirement visible anyway so that the necessary packages are installed before setup.py
is called? Should I move the compilation to a different file that is then called from setup.py
? How would I do that?
ANSWER
Answered 2019-Dec-29 at 17:22These are many broad questions. It is difficult to give an exhaustive answer and to keep opinions aside...
When it comes strictly to packaging Python projects, I believe pip's "requirements" files are not commonly useful nor used (there are counter examples of course, but I would argue that they are not a good idea for packaging in general). But in some other use cases, I believe they are very helpful.
If setuptools is used for packaging (there are perfectly valid alternatives), then install_requires
is the way to go to declare the direct dependencies of the project. Unless there is no other way around, then I would recommend placing the whole setuptools configuration (this includes install_requires
) in the setup.cfg
file instead of as arguments to setuptools.setup()
. The result would be exactly the same in both cases but (as it is now commonly accepted) for configuration, a static declarative file is a much more natural fit than executable code. As for the order of precedence, I believe a setuptools.setup()
argument would override the same configuration item read from setup.cfg
.
Would e.g. pip first execute
setup.py
and then check therequirements.txt
afterwards?
These are two different things. The requirements file is more or less a list of projects that one wants to install. Each of these projects might be packaged (setuptools or other) and distributed (source or pre-built wheel) in different ways, some will require the execution of a setup.py
some won't. But again, when packaging (and distributing) a project there is usually no need to bother with a requirements file (never when the project is a library, and not at first when the project is an application, see Donald Stufft's article "setup.py vs requirements.txt").
I would rather not go into details regarding the question about the combination of Cython and setuptools. It would be a good additional question. These two links might help get you started though:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install python-packaging
You can use python-packaging like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page