Search code examples
pythoncondagnu-screen

Screen inside conda environment doesn't use python PATH


I have a conda environment that is running python 3.10.5. It works on the terminal without screen. First I did

conda deactivate

And conda info at this step shows:

     active environment : base
    active env location : /home/myuser/anaconda3
            shell level : 1
       user config file : /home/myuser/.condarc
 populated config files : 
          conda version : 4.13.0
    conda-build version : 3.21.8
         python version : 3.9.12.final.0
       virtual packages : __cuda=10.2=0
                          __linux=5.4.0=0
                          __glibc=2.27=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/myuser/anaconda3  (writable)
      conda av data dir : /home/myuser/anaconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/myuser/anaconda3/pkgs
                          /home/myuser/.conda/pkgs
       envs directories : /home/myuser/anaconda3/envs
                          /home/myuser/.conda/envs
               platform : linux-64
             user-agent : conda/4.13.0 requests/2.27.1 CPython/3.9.12 Linux/5.4.0-109-generic ubuntu/18.04.6 glibc/2.27
                UID:GID : 1001272705:1000000513
             netrc file : None
           offline mode : False

then I did

screen -S scren_name

and the conda info at this step is

     active environment : base
    active env location : /home/myuser/anaconda3
            shell level : 1
       user config file : /home/myuser/.condarc
 populated config files : 
          conda version : 4.13.0
    conda-build version : 3.21.8
         python version : 3.9.12.final.0
       virtual packages : __cuda=10.2=0
                          __linux=5.4.0=0
                          __glibc=2.27=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/myuser/anaconda3  (writable)
      conda av data dir : /home/myuser/anaconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/myuser/anaconda3/pkgs
                          /home/myuser/.conda/pkgs
       envs directories : /home/myuser/anaconda3/envs
                          /home/myuser/.conda/envs
               platform : linux-64
             user-agent : conda/4.13.0 requests/2.27.1 CPython/3.9.12 Linux/5.4.0-109-generic ubuntu/18.04.6 glibc/2.27
                UID:GID : 1001272705:1000000513
             netrc file : None
           offline mode : False

then I activated the environment in screen. Now conda info says

     active environment : catvehicle
    active env location : /home/myuser/anaconda3/envs/catvehicle
            shell level : 2
       user config file : /home/myuser/.condarc
 populated config files : 
          conda version : 4.13.0
    conda-build version : 3.21.8
         python version : 3.9.12.final.0
       virtual packages : __cuda=10.2=0
                          __linux=5.4.0=0
                          __glibc=2.27=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/myuser/anaconda3  (writable)
      conda av data dir : /home/myuser/anaconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/myuser/anaconda3/pkgs
                          /home/myuser/.conda/pkgs
       envs directories : /home/myuser/anaconda3/envs
                          /home/myuser/.conda/envs
               platform : linux-64
             user-agent : conda/4.13.0 requests/2.27.1 CPython/3.9.12 Linux/5.4.0-109-generic ubuntu/18.04.6 glibc/2.27
                UID:GID : 1001272705:1000000513
             netrc file : None
           offline mode : False

However, when I write python in screen, the version shown is the default Ubuntu 18.04 included python which is 2.7, and not the 3.10.5 version that was part of my conda env.

how can I fix this, or make it use the proper python?


Solution

  • Edit: as mentioned by other users, setting an alias is not recommended. I was able to fix it by:

    1. Entering screen
    2. Writing conda deactivate until the (base) environment was no longer activated either.
    3. Writing conda activate my_env to activate.

    Now the python path is correct.