Search code examples
python-3.xlinuxpippython-venv

python3 incorrectly configured?


I have an OL7 Linux machine behind a firewall and with access only to python 3.6 in the repo.

Python 3.6 was installed in 2018 but never used and now I need to import some modules, but could not because the version requirement isn't met.

To this end I downloaded and manually installed 3.11.2, apparently successfully:

server:user:/home/user $ python3 --version
Python 3.11.2

According to root I have a good setup:

server:root:/usr/local/bin $ python3 -m ensurepip --default-pip
Looking in links: /tmp/tmp0p21jg5t
Requirement already satisfied: setuptools in /usr/local/lib/python3.11/site-packages (65.5.0)
Requirement already satisfied: pip in /usr/local/lib/python3.11/site-packages (22.3.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

However I can't run pip in either of the two recommended ways:

server:user:/var/tmp $ python3 -m pip --user install numpy-1.24.2.tar.gz
/usr/local/bin/python3: No module named pip.__main__; 'pip' is a package and cannot be directly executed

server:user:/var/tmp $ pip3 install --user numpy-1.24.2.tar.gz
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal'

When I tried to run python3 -m ensurepip --default-pip as my user it failed because I lack write permission to /usr/local/lib/python3.11/site-packages/setuptools-65.5.0.dist-info so I tried to create a venv:

server:user:/var/tmp $ python3 -m -venv /home/user/python3_venv
/usr/local/bin/python3: No module named -venv

Clearly there is something wrong with my environment, but what?

In terms of install all I've run is:

  119  make clean
  120  ./configure --enable-optimizations
  121  make
  122  make test
  123  make install

I had to abandon make test because of the lack of internet access but otherwise it seemed OK.

I'm not sure it is relevant but /usr/local/bin is in my user's PATH, but isn't in the default root PATH used at build time.

Other things I've tried is to remove the 3.6 environment, including pip, but that hasn't helped.

What can I try next?


Solution

  • It turns out that the site-packages directory was built with 700/600 permissions for files/directories.

    The fix is to grant the missing permissions:

    server:root:/var/tmp $ find /usr/local/lib/python3.11/site-packages -type d -exec chmod 755 {} \;
    seerver:root:/var/tmp $ find /usr/local/lib/python3.11/site-packages -type f -exec chmod go+r {} \;
    

    Now running as my user I get:

    server:user:/var/tmp $ pip list
    Package    Version
    ---------- -------
    pip        22.3.1
    setuptools 65.5.0
    WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
    WARNING: There was an error checking the latest version of pip.
    

    I think there may be other files I can't see, if I find any I'll update this answer.