Make (install from source) python without running tests
The configure option --enable-optimizations enables running test suites to generate data for profiling Python. The resulting python binary has better performance in executing python code. Improvements noted here
From configure help:
--enable-optimizations Enable expensive optimizations (PGO, etc). Disabled by default.
From wikipedia
profile-guided optimisation uses the results of profiling test runs of the instrumented program to optimize the final generated code.
In short, you should not skip tests when using --enable-optimizations as the data required for profiling is generated by running tests.
You can run make -j8 build_all
followed by make -j8 install
to skip tests once(the tests would still run with install
target), but that would defeat the purpose.
You can instead drop the configure flag for better build times.
Build python from source without creating symlink for binary
make altinstall
is made exactly for that:
make install
can overwrite or masquerade the python3 binary.make altinstall
is therefore recommended instead ofmake install
since it
only installsexec_prefix/bin/pythonversion
.
How to run tests without installing package?
I know this question has been already closed, but a simple way I often use is to call pytest
via python -m
, from the root (the parent of the package).
$ python -m pytest tests
This works because -m
option adds the current directory to the python path, and hence mypkg
is detected as a local package (not as the installed).
See:
https://docs.pytest.org/en/latest/usage.html#calling-pytest-through-python-m-pytest
building Python from source with zlib support
The solution is to install the Ubuntu package dpkg-dev
.
sudo apt-get install dpkg-dev
The reason is explained here.
In short, recent versions of Ubuntu don't store libz.so
in the standard /usr/lib
location, but rather in a platform specific location. For example, on my system is is in /usr/lib/x86_64-linux-gnu
. This prevents Python's build system from finding it.
The dpkg-dev
package installs the dpkg-architecture
executable, which enables Python to find the necessary libraries.
The original question was about Python 3.2.3. I also downloaded Python 2.7.3 and confirmed that the same problem exists, and this solution is applicable to it as well.
Does it make sense to install my Python unit tests in site-packages?
After researching this issue, and until someone more experienced has a minute to weigh in to the contrary, my understanding is that the simple answer is: "No, unit tests should not be installed, only included in the source distribution".
In the handful of cases I found where tests were installed, all turned out to be accidental and it's easier than one might think to make the mistake without noticing it.
Here's how it happens:
- The
packages=find_packages()
parameter is used in setup.py so packages can be found without having to list them out explicitly. - The
test
folder is made into a package (by adding__init__.py
) so tests can reference the modules they test using relative naming (likefrom .. import pkg.mod
). setuptools
installstest
as a separate package, alongside the other(s) in the project. Note this means you can executeimport test
in the python interpreter and it works, almost certainly not what you intended, especially since a lot of other folks use that name for their test directory :)
The fix is to use the setting: packages=find_packages(exclude=['test'])
to prevent your test directory from being installed.
Install python on Linux from source with custom paths
The process is quite straight forward, let's say you want to install in your $HOME
# 0) Download python source and extracted it to $HOME/tmp/Python3.9.2 directory
# 1)
mkdir $HOME/usr
# 2)
cd $HOME/tmp/Python3.9.2
# 3)
./configure --prefix=$HOME/usr && make
# 4) Now python is built in $HOME/tmp/Python3.9.2, give it a test, then
make install
# Now you should have $HOME/usr/bin/python ready to use.
Related Topics
Checking Running Python Script Within the Python Script
Why Can't Python Sockets Resolve Url's with Http in It
Visibility of Global Variables in Imported Modules
Getting a List of Values from a List of Dicts
Pg_Config Executable Not Found
How to Redirect Output with Subprocess in Python
What Do Ellipsis [...] Mean in a List
What Does "Hashable" Mean in Python
Common Elements Comparison Between 2 Lists
Slice 2D Array into Smaller 2D Arrays
Unicodedecodeerror Reading Binary Input
Passing Variable from Python Script to Bash Script
Instance Variables VS. Class Variables in Python
How to Keep Python Print from Adding Newlines or Spaces
How to Return Dictionary Keys as a List in Python
Getting Python Error "From: Can't Read /Var/Mail/Bio"