Using exec:
version = {} with open("...sample/version.py") as fp: exec(fp.read(), version) # later on we use: version['__version__']
You can also define the version in the __init__.py
of your package like:
__version__ = "1.1.0"
Step 1: Install versioneer
pip install versionner
Step 2: Execute versioneer
versioneer install
In the setup.py you'll have to add something like:
import versioneer
setup(
version = versioneer.get_version(),
cmdclass = versioneer.get_cmdclass()
)
After that, try:
python setup.py version
Discussions Deploying Python applications pip vs easy_install install_requires vs requirements files Wheel vs Egg ,Whereas install_requires defines the dependencies for a single project, Requirements Files are often used to define the requirements for a complete Python environment.,Whereas install_requires requirements are minimal, requirements files often contain an exhaustive listing of pinned versions for the purpose of achieving repeatable installations of a complete environment.,Whereas install_requires metadata is automatically analyzed by pip during an install, requirements files are not, and only are used when a user specifically installs them using python -m pip install -r.
install_requires = [
'A',
'B'
]
install_requires = [
'A>=1',
'B>=2'
]
install_requires = [
'A>=1,<2',
'B>=2'
]
Requirements files are used to hold the result from pip freeze for the purpose of achieving Repeatable Installs. In this case, your requirement file contains a pinned version of everything that was installed when pip freeze was run.,Constraints files are used for exactly the same reason as requirements files when you don’t know exactly what things you want to install. For instance, say that the “helloworld” package doesn’t work in your environment, so you have a local patched version. Some things you install depend on “helloworld”, and some don’t.,Requirements files are used to hold the result from pip freeze for the purpose of achieving Repeatable Installs. In this case, your requirement file contains a pinned version of everything that was installed when pip freeze was run. Unix/macOS python -m pip freeze > requirements.txt python -m pip install -r requirements.txt Windows py -m pip freeze > requirements.txt py -m pip install -r requirements.txt ,If you want to process the output further, use one of the other APIs in the module. We are using freeze here which outputs installed packages in requirements format.:
python -m pip <pip arguments>
py -m pip <pip arguments>
python - m pip install SomePackage # latest version python - m pip install SomePackage == 1.0 .4 # specific version python - m pip install 'SomePackage>=1.0.4' # minimum version
py - m pip install SomePackage # latest version py - m pip install SomePackage == 1.0 .4 # specific version py - m pip install 'SomePackage>=1.0.4' # minimum version
python - m pip install - r requirements.txt
py - m pip install - r requirements.txt
This is where a package declares its core dependencies, without which it won’t be able to run. setuptools supports automatically downloading and installing these dependencies when the package is installed. Although there is more finesse to it, let’s start with a simple example.,Setuptools allows you to declare dependencies that are not installed by default. This effectively means that you can create a “variant” of your package with a set of extra functionalities.,Historically setuptools also used to support extra dependencies in console scripts, for example:,Dependencies that are not available on a package index but can be downloaded elsewhere in the form of a source repository or archive may be specified using a variant of PEP 440’s direct references:
[build - system] requires = ["setuptools"] #...
[project] #... dependencies = [ "docutils", "BazSpam == 1.1", ] #...
[options] #... install_requires = docutils BazSpam == 1.1
setup(
...,
install_requires = [
'docutils',
'BazSpam ==1.1',
],
)
[project] #... dependencies = [ "enum34; python_version<'3.4'", ] #...
[options] #... install_requires = enum34; python_version < '3.4'