0

I'm trying to understand Linux OS library dependencies to effectively run python 3.9 and imported pip packages to work. Is there a requirement for GCC to be installed for pip modules with c extention modules to run? What system libraries does Python's interpreter (CPython) depends on?

2
  • 1
    Run ldd on the python executable. You don't need GCC to run Python, but you do need it to build it, and to build certain packages from pip. Commented May 23, 2021 at 1:14
  • 1
    Python is a language—it is an abstract computing environment that can be ported to any sufficiently capable system. Specific Python implementations may depend on things like C compilers or operating system features. Commented May 23, 2021 at 1:32

3 Answers 3

3

I'm trying to understand Linux OS library dependencies to effectively run python 3.9 and imported pip packages to work.

Your questions may have pretty broad answers and depend on a bunch of input factors you haven't mentioned.

Is there a requirement for GCC to be installed for pip modules with c extention modules to run?

It depends how the package is built and shipped. If it is available only as a source distribution (sdist), then yes. Obviously a compiler is needed to take the .c files and produce a laudable binary extension (ELF or DLL). Some packages ship binary distributions, where the publisher does the compilation for you. Of course this is more of a burden on the publisher, as they must support many possible target machines.

What system libraries does Python's interpreter depends on?

It depends on a number of things, including which interpreter (there are multiple!) and how it was built and packaged. Even constraining the discussion to CPython (the canonical interpreter), this may vary widely.

The simplest thing to do is whatever your Linux distro has decided for you; just apt install python3 or whatever, and don't think too hard about it. Most distros ship dynamically-linked packages; these will depend on a small number of "common" libraries (e.g. libc, libz, etc). Some distros will statically-link the Python library into the interpreter -- IOW the python3 executable will not depend on libpython3.so. Other distros will dynamically link against libpython.

What dependencies will external modules (e.g. from PyPI) have? Well that completely depends on the package in question!

Hopefully this helps you understand the limitations of your question. If you need more specific answers, you'll need to either do your own research, or provide a more specific question.

Sign up to request clarification or add additional context in comments.

Comments

1

Python depends on compilers and a lot of other tools if you're going to compile the source (from the repository). This is from the offical repository, telling you what you need to compile it from source, check it out.

1.4. Install dependencies This section explains how to install additional extensions (e.g. zlib) on Linux and macOs/OS X. On Windows, extensions are already included and built automatically.

1.4.1. Linux

For UNIX based systems, we try to use system libraries whenever available. This means optional components will only build if the relevant system headers are available. The best way to obtain the appropriate headers will vary by distribution, but the appropriate commands for some popular distributions are below.

However, if you just want to run python programs, all you need is the python binary (and the libraries your script wants to use). The binary is usually at /usr/bin/python3 or /usr/bin/python3.9

Python GitHub Repository

For individual packages, it depends on the package.

Further reading:

2 Comments

It's just to run python programs. But will the extension modules comes with pip packages will have a dependency on C compilers? I'm trying to understand at which level does python depend on OS/kernel libraries.
@Gladiator That depends on each package. Check the edit for some references.
0

However, if you just want to run python programs, all you need is the python binary (and the libraries your script wants to use). The binary is usually at /usr/bin/python3 or /usr/bin/python3.9

This is incorrect, python depends on a number of Linux c libs which must be present. This is particularly important if you're looking to build distroless python images as they will not be present by default.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.