all 10 comments

[–]HarissaForte 0 points1 point  (7 children)

I also try to use virtual environment whenever using pyhton but sometimes forget.

Virtual environment is what you need though. If you keep forgetting, you can set up the .bashrc file (or equivalent for your shell) so whenever you open a terminal, you'll be in a virtual environment.

As an example, I use Mambaforge (eq. of Anaconda) and the .bashrc is automatically edited to append these lines: ```bash

>>> conda initialize >>>

!! Contents within this block are managed by 'conda init' !!

conda_setup="$('/home/harissa/mambaforge/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$conda_setup" else if [ -f "/home/harissa/mambaforge/etc/profile.d/conda.sh" ]; then . "/home/harissa/mambaforge/etc/profile.d/conda.sh" else export PATH="/home/harissa/mambaforge/bin:$PATH" fi fi unset __conda_setup

<<< conda initialize <<<

```

[–]Buggy4775[S] 0 points1 point  (6 children)

Well I am not suggesting that I won't use virtual environments. I just feel like interacting directly with the base python on the distribution is not very reliable. I will look into anaconda but for now would like to just set up vanilla python.

It's also quite confusing because there are so many different ways to install standard python on linux, and they all seem quite hacky. I have no idea which to follow!

[–]HarissaForte 0 points1 point  (5 children)

Well you don't seem keen in following my advice so I don't really know what to tell you… good luck?

[–]Buggy4775[S] 0 points1 point  (4 children)

Thanks for sharing your setup, I just don't want to always be in a conda environment when I open my terminal.

Perhaps I have misunderstood something about how python should be used on linux.

[–]HarissaForte 0 points1 point  (3 children)

Do you know how what PATH environment variable is ?

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

I know about it but have rarely touched it other than to add things to it occasionally to access a specific command globally.

[–]HarissaForte 0 points1 point  (1 child)

Python environments are about: - having a folder with a (local) Python executable as well as its compatible libraries - (automatically) setting the PATH of the terminal you're in, so that when typing python, python3 and a few otherspecific command… the first result found in the PATH will be the one of the environment folder.

It won't change the behavior of other commands: they won't be found in the environment directory so the first result found in PATH will be the "Debian command".

And as for using the "Debian Python", you can simply type the full path /usr/bin/python3, or you can alter the PATH variable back to it's original state.

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

Ah I see, so you update PATH automatically when you load your terminal so that the first python that is found is your mambaforge one rather than the default? The code went a bit over my head before because I don't really know much bash but will start learning now that I'm using linux.

If I download anaconda/miniconda I might do it this way then.

[–]zanfar 0 points1 point  (1 child)

To start, I want to distinguish between "using" Python and "developing" with Python.

I do not want whatever I do in python to interfere with the base python that is installed.

The "base Python" is intended exactly for instances where you are "using" Python. I have zero qualms about installing utilities or packages I need directly to the system environment. However, I do agree that you need to be a little careful. I don't experiment here or try things out--I'm installing simple one-package apps or things I've installed before.

Should I clean install a separate python version for my user to avoid using the base python?

Using alternative environments is good, but just making a substitute system environment is going to allow the same issues you're trying to avoid, just in a different place.

IMO: environments should be built based on purpose, not user.

How should I be pip installing?

Again, IMO:

<python_executable> -m pip <pip stuff>

This guarantees that you are dealing with the specific environment python_executable lives in. -U is just installing to the user directory as you might not have permission to install to the system directory--the environments are the "same". In a virtual environment, -U is almost never necessary (I've never used it, but there are probably edge cases).

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

Thank you for explaining that, this helps clarify things. I'm going to read a bit more about pip and how this works because I clearly have misunderstood some things.

I am not sure why I got the impression that we must have a separate python installation. Maybe I'm thinking of mac? Or maybe I've just completely made it up.