0

I'm currently working on a remote server (through ssh) and I need to load some modules (module load [package1][package2] ecc). Specifically, it's required the numpy version 1.15.2, but in the directory containing all the numpy versions there are only 1.14.0 versions.

Anyway, I was able to get the package numpy/1.15.2--python--3.6.4 (which I obviously don't have permission to copy in the directory containing the other versions of numpy) so I was wondering if I could (and how) temporarely change the enviromental variable path in order to specify, only in that case, where the "module load" should look for, instead of the usual repository like for other modules.

  • Typically, for importing modules, you need to change the `PYTHONPATH` or the `sys.path` in Python, not the system-wide `PATH` (which is used to find executables, not Python modules). – Charles Duffy Jun 02 '21 at 19:07
  • Also, _all_ environment variable updates are temporary by nature unless you go out of your way to generate code or configuration that changes them permanently, so it's really not clear at all what you're asking for. – Charles Duffy Jun 02 '21 at 19:08

2 Answers2

0

temporarely change the enviromental variable path

I think the easiest would be to create a subshell with the modified PATH and work in that:

PATH=modifiedpath bash 

Whether this works or not, depends on what exactly you are doing in your .bashrc with your PATH. If you reassinged there the old PATH, your changes would be lost and in this case, you could instead do a

PATH=modifiedpath bash --norc

to bypass soucring .bashrc. Of course this means aliases, functions and non-exported variables from your .bashrc aren't available either.

If this too causes a problem, you could stay in your shell, but temporarily safe the PATH:

origpath=$PATH
PATH=modifiedpath
... do your work
PATH=$origpath # restore it
user1934428
  • 19,864
  • 7
  • 42
  • 87
  • PATH changes should be made in `.bash_profile` (or just `.profile`), not `.bashrc`, so if someone is following good practices, an interactive non-login shell will just inherit its parent process's PATH without overriding any part of it. (`.bashrc` is for things like aliases and non-exported variables that aren't shared through the environment). – Charles Duffy Jun 02 '21 at 19:09
  • For permanent changes, yes. The OP explicitly asks for a **temporarily** change, and IMO this indeed may make sense. I do this for instance for testing, after having installed a new version of a program somewhere. In this case, I have one shell with the new directory in the PATH, and another one with the old setting, and I can easily compare these setups. – user1934428 Jun 03 '21 at 10:12
  • I'm not talking about how to enact a permanent change. I'm arguing that if bash is configured according to best-practice / convention, `.bashrc` won't do anything that stops `PATH=modifiedpath bash -i` from working even without `--norc`. – Charles Duffy Jun 03 '21 at 11:45
  • @CharlesDuffy: If `.bashrc` stuffs new directories to the end of the PATH, and _modifiedpath_ places the directories which might be of concern here to the start of the PATH, it would work. We don't know how the OP wrotes his .bashrc, and I don't know how `module load` fiddles with the PATH. i can't argue anything here .... – user1934428 Jun 04 '21 at 05:24
  • 1
    What you're saying is true. I'm arguing only that someone who made their .bashrc modify PATH _is Doing It Wrong_, because only .bash_profile should do that; they'll have undesirable side effects, like multiple copies of the same string being appended, whenever a process started by an interactive shell starts a second interactive shell. – Charles Duffy Jun 04 '21 at 10:54
0

You could have your own modulepath that supersedes the modulepaths provided by the admins on the system you use.

Just create a directory structure, then add your own numpy/version modulefile in it (such modulefile should define the environment variables to use your specific installation of the numpy package).

$ mkdir ~/modulefiles
$ mkdir ~/modulefiles/numpy
$ $EDITOR ~/modulefiles/numpy/<version>

Then enable this modulepath in your current shell session:

$ module use ~/modulefiles

Lastly added modulepath gets higher priority, so when you will perform the module load numpy command it will load your specific numpy modulefile instead of the numpy modulefile provided by default.