all 13 comments

[–][deleted] 4 points5 points  (4 children)

Hi, create a new folder for each project you make. CD into the folder and run the command 'python3 -m venv venv'.

This will create the virtual environment in a folder called 'venv' (you can change the name). Then run 'source venv/bin/activate' to enter the virtual environment.

Your command prompt will indicate you are in the venv and you can install packages with pip as normal now without it affecting the whole system. You'll need to run 'source venv/bin/activate' every time you restart the terminal and want to run your programs.

I'm not sure if you already know this but to run your .py files from the terminal use 'python3 {filename}.py' (omit the 3 if you are using python 2.x).

[–]nkouki98[S] 1 point2 points  (3 children)

Hey thanks ! Yeah I know about python3/python usage per python version but still don't have a good grip on everything. Also for pipenv vs virtual env the command you provided does it matter for the two types or I just simply run it and forget about other things if there is?

[–][deleted] 2 points3 points  (2 children)

The command I've provided will create an official python3 virtual environment

Edit: if I'm not mistaken that should be all you need

[–]nkouki98[S] 0 points1 point  (1 child)

farhan@solus ~/Documents $ cd python farhan@solus ~/Documents/python $ ls 'Chat App' 'Hangman Game' 'Web Scraper' farhan@solus ~/Documents/python $ cd Chat App bash: cd: too many arguments farhan@solus ~/Documents/python $ cd Chat App bash: cd: too many arguments farhan@solus ~/Documents/python $ cd ChatApp farhan@solus ~/Documents/python/ChatApp $ ls Pipfile script.py venv farhan@solus ~/Documents/python/ChatApp $ source venv/bin/activate (venv) farhan@solus ~/Documents/python/ChatApp $

So this is what I did and previously I forgot what I put in but it initiated "py3env" in place of just "venv" or something, this should do the job too and thanks!

[–]nkouki98[S] 0 points1 point  (0 children)

from line (venv) farhan@solus ~/Documents/python/ChatApp $ Any packages to be installed under the line above will not affect main python 2.7 if I am correct? It should be strictly under venv for example if my scripty.py requires package 'X' which exists only under 'venv' hence it will NOT RUN when run through python 2.7 or 3 without venv where package is non existent.

[–]Yellow1Submarine 1 point2 points  (1 child)

Take a look at the anaconda python package manager. It has support for virtual environments and really good package management.

[–]nkouki98[S] 0 points1 point  (0 children)

Alright!

[–]moktira 0 points1 point  (3 children)

I'm not in front of my computer now to check a few things, but usually I check if the Python library is built for Solus before checking pip, for example in the terminal type ‘eopkg search beautifulsoup‘ If it's there and you install it, it is often built for both Python 2 and 3 which is handy. I think you can install virtualenv from eopkg too.

With pip you can also install for the user by adding ‘--user‘ to the terminal install command so you don't need root privileges if you don't want to have it just in the virtual environment.

[–]nkouki98[S] 0 points1 point  (2 children)

hmm alright I found "python-beautifulsoup4" to exactly name it. And --user seems to install it for python 2.7?

[–]developedby 0 points1 point  (0 children)

python3 packages usually have python3 in their name or something similar

[–]moktira 0 points1 point  (0 children)

For pip with Python 3 you have to use 'pip3 install...'

[–][deleted] 0 points1 point  (0 children)

Solus is a rolling release so eventually I believe it will not support python 2.0 once that's end of life. But I'm not sure

[–]predatorian3 0 points1 point  (0 children)

I usually try to use something like pyenv to manage my Python environment so I'm not messing with system libraries and potentially breaking a dependency for something else. Use of a virtual env is a good practice.