-
Notifications
You must be signed in to change notification settings - Fork 0
Build Python Environment
There is a compiled Python 3.6 in /home/aardvark/tools/.local/python3/bin/python3.6 and also a system Python 3.2 in /usr/bin/python on r2d2. With an existing Python, one could easily build a Python virtual environment.
Create a link file of Python3 to /home/envs/local/bin
venv@r2d2:~/local/bin$ ln -s /home/aardvark/tools/.local/python3/bin/python3.6 /home/envs/local/bin/python3.6
venv@r2d2:~/local/bin$ ln -s /home/envs/local/bin/python3.6 /home/envs/local/bin/python3
Here I use the user venv as an example. If you want to create Python virtual environment for your own, you don't need to switch to venv.
Create a folder for virtual environment with command /path/to/python /path/to/virtualenv.py /path/to/folder. Remember to use the correct Python. So it is better to provide the full path to that Python.
venv@r2d2:~$ /home/envs/local/bin/python3 /home/envs/packages/virtualenv-15.1.0/virtualenv.py /home/envs/VENV/PYENV
Using base prefix '/home/aardvark/tools/.local/python3'
New python executable in /home/envs/VENV/PYENV/bin/python3
Also creating executable in /home/envs/VENV/PYENV/bin/python
Installing setuptools, pip, wheel...done.
Then in the folder which you set the path and name, pip has been generated inside (/home/envs/VENV/PYENV/bin/pip).
Activate this virtual environment and the default Python in this environment is the one you set when creating this environment.
venv@r2d2:~$ source /home/envs/VENV/PYENV/bin/activate
(PYENV) venv@r2d2:~$ which python
/home/envs/VENV/PYENV/bin/python
The virtual user venv is created for managing all virtual environments and its password is passwd4venv.
tao@r2d2:~$ sudo useradd venv
[sudo] password for tao:
tao@r2d2:~$ sudo passwd venv
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
# Set home directory for it and add groups:
tao@r2d2:~$ sudo usermod -d /home/envs -g users venv
When managing virtual environments, switch to user venv by su venv, and
$ sudo ./configure --prefix=/usr/local/pythons
$ sudo make
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_dbm _gdbm _ssl
_uuid
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc atexit pwd
time
Failed to build these modules:
_ctypes _lzma
For lzma, download source package xz-5.2.4 (there might be problems if use other versions of xz) which in /home/tao/packages/xz-5.2.4.tar.gz, and unzip it by tar xzf xz-5.2.4.tar.gz.
tao@r2d2:/home/envs/packages/xz-5.2.4$ ./configure --prefix=/home/envs/local
XZ Utils 5.2.4
...
tao@r2d2:/home/envs/packages/xz-5.2.4$ make -j4 & make install
Rebuild Python
tao@r2d2:/home/envs/packages/Python-3.7.2$ ./configure --prefix=/home/envs/pythons LDFLAGS="-L/home/envs/local/lib"