We want to exclude the Python source code from the package we create. But after configuring setup.py, I failed excluding the py files. I have been using python setup.py bdist_wheel as command. Is there any way to exclude to source code from Python package? Basically we do not want to expose the source codes.
The wheel plugin for setuptools that handles bdist_wheel does not have the --exclude_source_files which is only supported by bdist_egg. The egg packages are however deprecated and not supported by pip for example. What you can do however:
pip3 install wheel
python3 setup.py bdist_egg --exclude-source-files
wheel convert dist/mypackage-1.0-py3.6.egg
The wheel utility takes a source-stripped egg and converts it into whl package.
This came up for us putting Python libs on an embedded system with very minimal available memory.
It can be achieved with:
./setup.py bdist_egg --exclude_source_files
Works for both distutils and setuptools.
Well, we also encountered this issue (around 2 years ago) and didn't find a sensible automation process for it. So I wrote my own.
You're welcomed to it: setup.py template
Related
Is there any way to get the list of packages specified in the install_requires parameter to the setup command (in setup.py)?
I'm looking for something similar to pip show pkgname | grep -i requires, but for local packages (and that reports version specifiers and filters).
The real task I'm solving is to check if versions specified in setup.py and requirements.txt have diverged, so if there is a tool that can do this directly...?
For installed packages, use stdlib importlib.metadata.requires. Python 3.8+ is required, but there is a backport importlib-metadata for older Python versions. This is the easy case, because installed packages have already generated the metadata (including dependency specs) at installation time. For local source trees which aren't necessarily installed, read on.
There is a way to do this in Python APIs via distutils (which setuptools wraps):
import distutils.core
dist = distutils.core.run_setup("setup.py")
for req in dist.install_requires:
print(req)
As a shell command that might look like:
python -c 'import distutils.core; print(*distutils.core.run_setup("setup.py").install_requires, sep="\n")'
It is also possible to use the CLI to generate egg-info and then read deps from that:
python setup.py egg_info
cat myproject.egg-info/requires.txt
However, distutils is deprecated and setuptools is trying to be a library only, so using setup.py in this way is quite neglected.
You might consider moving to declarative dependencies specified in pyproject.toml and then just reading the requirements directly with a simple TOML parser.
Every time I boot up terminal on VSCode, I get the following prompt. This does not happen on Terminal.app.
/usr/local/lib/python3.9/site-packages/setuptools/command/install.py:34:
SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip
and other standards-based tools.
How do I resolve this?
Install the setuptools 58.2.0 version using the following command
pip install setuptools==58.2.0
I assume you stumbled across this issue when you was building your .whl-file doing something like python Setup.py bdist_wheel --dist-dir .. (If not: This answer probably not applies to your problem.)
The warning you see wants to say that calling python Setup.py ... is obsolete now.
Solution, in short:
Replace setup.py with pyproject.toml. In pyproject.toml you enter all values from setup.py in an INI-file-like-structure. Then you create your .whl-file using the command python -m build.
Further information about python-packages and pyproject.toml: https://packaging.python.org/en/latest/tutorials/packaging-projects/
Further information about how to use pyproject.toml using setuptools:
https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html
Upgrade the setuptools. The versions greater than 58.2.0 is not showing the deprecation warning as of Oct 18, 2022.
pip install -U setuptools
Note, there are many ways to package Python. You will want to evaluate where your target deployment is. Working with the TOML files is a trend that allows better integration with many software languages. Reference: Overview of Packaging for Python
Install the setuptools 58.2.0 version using the following command
pip install setuptools==58.2.0
Don't upgrade the setuptools. Only the version 58.2.0 worked for me. Though I tried upgrading the version to 65.5.0 but it was showing the deprecation warning.
I was having same issue for my data science project. I got same error while running pip install -r requirements.txt. This Worked for me.
Calling setup.py directly is being deprecated, as explained here.
I did as the message told me and now build the wheel using pip (it still calls setup.py internally):
pip wheel --no-deps -w dist .
This replaced my old equivalent code:
python setup.py bdist_wheel
Note that the pip wheel command creates the wheel into your current directory by default, which is why I specify -w/--wheel_dir to match the old behavior of using the ./dist directory.
I also specify --no-deps so pip does not download the wheel files of all dependencies.
I am trying to install a library in a virtualenv instance with pip. The library version I want (wxPython 3.0.2)
is not available on PyPi; it is only available for download from SourceForge. Thus, I have the source tarball downloaded on my machine and I am trying to install it in such a way that it will play nicely with virtualenv.
(I am on a Windows computer, running Python 2.7.)
I have tried the following:
doing a direct install: pip install wxPython-src-3.0.2.0.tar.bz2
extracting the files from the tarball to wxPython-src-3.0.2.0, then installing from the extracted directory: pip install wxPython-src-3.0.2.0
extracting the files from the tarball, then navigating into the extracted folder to the nested wxPython directory, which holds the setup.py file, and then installing from there: pip install wxPython
The last attempt seems the most promising, but I get the following traceback:
Processing \wxpython-src-3.0.2.0\wxpython
Complete output from command python setup.py egg_info:
Setuptools must be installed to build an egg
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\__MY_USERNAME__\appdata\local\temp\pip-req-build-q0pxlt\
This is also strange, because it suggests I don't have setuptools even though I can run pip list and see version 40.6.3 installed.
Any help appreciated.
Why not install a precompiled version? There are a lot of .exe files at SF. You probably need wxPython3.0-win64-3.0.2.0-py27.exe.
Also take a look at Christoph Gohlke's collection.
If you still insist on installing from sources please bear in mind that wxPython 3 is so old it predates pip. Forget about pip.
First, you need to install wxWidgets as wxPython is just a Python wrapper for wxWidgets C++ library. Extract wxPython-src-3.0.2.0.tar.bz2 and follow instructions in wxPython-src-3.0.2.0/docs/msw/install.txt.
After compiling and installing wxWidgets compile wxPython. See wxPython-src-3.0.2.0/wxPython/docs/BUILD.txt.
My eventual solution was the easy way out: installing my package (wxPython) locally as #phd suggested, and opting for local package access via either virtualenv --system-site-packages env or deleting the "no-global-site-packages.txt" file in an existing environment folder.
Not what I expected to do, but it works so no complaints.
Is it possible to pip install package which provides optional C-extension, but specifically disable process of compiling those extensions?
Sample examples of such packages are:
_speedups in markupsafe
_posixsubprocess32 in subprocess32
It's not because it's setup.py that decides what and how to build. You have to download sources, unpack and edit setup.py to avoid building extensions.
My setup.py script is simple:
from distutils.core import setup
setup(name='my-awesome-app',
version='1.0',
scripts=['my-awesome-app.py'],
)
And the file structure is:
my-awesome-app/
my-awesome-app.py
setup.py
In theory I am only including my-awesome-app.py in the distribution. In practice setup.py ends up in the RPM too.
I don't see a point of including setup.py there, is there a way to force distutils to leave this file out?
I am using python 2.7, I build my RPM by running python setup.py bdist_rpm.
Thanks for help :)
setup.py is required because when the package is installed in your environment, the following command is run:
$ python setup.py install
Running python setup.py bdist_rpm only creates a distribution package that you can give to others. setup.py is still required to do the installation.
You can always create the spec file manually and leave out the setup.py.
For example and more details see:
https://fedoraproject.org/wiki/Packaging:Python#Example_common_spec_file