VIRTUAL ENVIRONMENT PYTHON

Virtual enironment creation to make system more stable.

ve virtual env with python and Development|lower


HOW TO CREATE VIRTUAL ENVIRONMENT FOR NEW PYTHON PROJECT

 

1. If you install external packages on main system it could cause conflicts. Virtual environment is a separate folder.

2. IDE can create virtual environment also.

3. To add virtual enviroment in Eclipse window→preferences→PyDev→Interpreter Set PATH to lib folder of your virtual enviroment. Find path with $ which python

3.1. To download use $ sudo apt install python3-venv

4. To create virt environment type $ python3 -m venv ~/venv

5. To start virtual environment $ source /venv/bin/activate

6. To stop type $ deactivate

7. To check packages in environment $ python3 -m pip list

8. Install packages that you need $ python -m pip install requests

9. I can’t install package. Got error ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/venv/lib/python3.8/site-packages/urllib3'

Consider using the `--user` option or check the permissions.

10. I’ve changed folder permission $ sudo chmod -R 766 python3.8

11. But now I get another error // /venv/bin/python: No module named pip

12. Probably pip was not installed // $ sudo apt install pip // Doesn’ work

13. I will try to delete and reinstall venv: $ sudo rm -rf /venv // Doesn’t work. Get again an ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/venv/lib/python3.8/site-packages/charset_normalizer-2.0.12.dist-info'

Consider using the `--user` option or check the permissions.

14. Try to add --user at the end $ python -m pip install requests –user // Doesn’t work.

15. May be problem because I used sudo to install venv. Try to reinstall without sudo.

16. I’ve installed it to my home user folder // It is work

 

INSTALL ANOTHER PYTHON VERSION

1. How to check which interpreters are installed. // $ whereis python3 or $ ls -ls /usr/bin/python*

2. How to install second version of python.

2.1. Check which versions available. // apt-cache madison <<package name>>

3. Download and unpack python you need from python.org/downloads/

3.1. $ sudo ./configure --enable-optimizations --prefix=/opt/Python3.9.0 --exec-prefix=/opt/Python3.9.0

3.2. $ sudo make

3.2.1 $ sudo make altinstall

3.3. Create virtual environment $ /opt/python3.9.0/bin/python3.9 -m venv ~/venv39

3.4. When I try to install something with $ pip install package I got an error "pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available."

3.4.1 Try $ sudo apt-get install libssl-dev zlib1g-dev build-essential libgdbm-dev libnss3-dev libreadline-dev libffi-dev libbz2-dev  // Didn't help

3.4.2. Try to manually move tensorflow from first python venv to my venv39  // Didn't help

3.4.3. Try to install python3.8.15 // pip installation started to work but tensorflow still doesn't work with new python.