Context:
I am trying to compile JModelica Ubuntu (running on WSL - Windows Subsystem for Linux) and facing a challenge with Python version conflicts. The compilation process requires Python 2, but by default, python on my system refers to a Python version managed by pyenv, specifically located at /mnt/c/Users/<userName>/.pyenv/pyenv-win/shims/python. This setup leads to errors during the JModelica compilation process, such as:
make[2]: Entering directory '/mnt/c/dev/JModelica/build'
...
python setup.py install --with_openmp=True ...
/mnt/c/Users/<userName>/.pyenv/pyenv-win/bin/pyenv: 3: cygpath: not found
/mnt/c/Users/<userName>/.pyenv/pyenv-win/bin/pyenv: 3: exec: cmd: not found
make[2]: *** [Makefile:1020: build-python-packages] Error 127
...
The compilation fails because it attempts to use the Python version managed by pyenv, which seems incompatible with the expected environment. Running which python confirms that python points to the pyenv shim: /mnt/c/Users/<userName>/.pyenv/pyenv-win/shims/python.
Question:
I have installed Python 2 using sudo apt install python2, and which python2 correctly points to /usr/bin/python2. However, I am unsure how to alias python to /usr/bin/python2 across the system or specifically for the JModelica compilation process, bypassing pyenv.
I have tried temporarily aliasing python to python2 in my current shell session
alias python=/usr/bin/python2
and adjusting the PATH environment variable so that /usr/bin takes precedence over the pyenv shims directory
export PATH=/usr/bin:$PATH
but neither approach resolves the issue during the JModelica build process.
Could someone guide me on how to force the Ubuntu operating system to recognize /usr/bin/python2 as the default python interpreter, especially for compiling JModelica, or how to adjust the build process to use the correct Python version?
Here is the solution I have found so far using virtual environments:
sudo apt install python-pippython2 -m pip install virtualenv~/.local/bin/virtualenv --python=/usr/bin/python2 jmodelica_envsource jmodelica_env/bin/activate