Error "can't create or remove files in install directory" when installing by source code in Python

Viewed 8218

I am trying to setup my Python environment in cloud Linux. I copied the working folder "Artem's_strategy", which contains the source code setup.py, from local PC to the cloud LInux system. When trying to install setup.py I get the following error

[ec2-user@ip-xxx Artem's_strategy]$ python3 setup.py install
running install
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 2] No such file or directory: '/usr/local/lib/python3.7/site-packages/test-easy-install-2160.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib/python3.7/site-packages/

This directory does not currently exist.  Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).

In other thread I found solution in the form of using --install-dir, which brings following error:

[ec2-user@ip-xxx~]$ /home/ec2-user/Artem\'s_strategy/setup.py --install-dir=/usr/local/lib/python3.7/site-packages
: No such file or directory

Checking the folder we can see that setup.py exists in this folder:

[ec2-user@ip-xxx Artem's_strategy]$ ls -la
total 1480
-rwxr-xr-x  1 ec2-user ec2-user     354 Mar 17 15:51 setup.py

So your help with installing from source code setup.py would be appreciated.

5 Answers

If you go into a terminal and execute:

python3 -m site

It should give you a response similar to the following:

sys.path = [
    '/home/tyler',
    '/usr/lib/python36.zip',
    '/usr/lib/python3.6',
    '/usr/lib/python3.6/lib-dynload',
    '/home/tyler/.local/lib/python3.6/site-packages',
    '/usr/local/lib/python3.6/dist-packages',
    '/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/tyler/.local' (exists)
USER_SITE: '/home/tyler/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True

Using this, you can determine the directory in which your site-packages are stored and use the

--install-dir

parameter to install it there. Hope this helps!

After finding where your site-packages are installed, use --prefix=location in your command.

python3 setup.py install prefix=C:\\Users\\User\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python38\\site-packages
Related