Ideally I would like to use Loading an Lmod module using VSCode with Remote-SSH
however the soultion to use that directly does not seem to work. On the other hand virtualenvs ought to be supported by the Python VSCode extension.
Thus I figured the following steps should work instead.
Set-up the virtualenvironment in the remote environment
$ module load Python
$ virtualenv --system-site-packages my_python
Connect via "Remote - SSH" plugin
In the terminal source your virtual environment from 1 and get the path to the python binary softlink:
$ source my_python/bin/activate
$ which python
/path/to/my_python/bin/python
Copy the path to the python binary and paste it into the path to the Python intepreter that VSCode asks for.
And they do, but not always. The first time I tried this it worked and now everytime I try this for the same host it works directly. However, whenever I change to another host with the same parallel file system and redo step 4 it doesn't and instead says
Invalid python interpreter selected
This is the same error message as when you try to directly point to the python that the is loaded with Lmod (and built with EasyBuild if that makes a difference).
Now I'm stuck because the error message is not very helpful, I haven't found a stacktrace or any log-files that include this error. If I could find that or the code that handles the logic for what is a valid interpreter, that would be really helpful.
In summary:
virtualenv --system-site-packages symlinked Python doesn't work reliably as interpreter when system site Python is not a valid Python interpreter.
How to get this to work reliably?
Alternatively, what is the logic that determines a valid interpreter?
Related
I am trying to use Pycharm to develop Libreoffice python Macro with in the virtual environment with not a lot of success. You'll find below a few things I have tried with the differnt errors I have had so far. I welcome any answers on the errors below as well as alternate solutions.
first try : set up directly the venv environment
As when you work with Libreoffice, you need to use the embedded python integrator, the first attempt is when defining the python integrator in pycharm, I reference this embedded interpreter (located somewhere in Program Files\Libreoffice\program` on my windows machine, I click the new venv box in pycharm and get the following error :
Error: standard python 'venv' module not found
So it seems venv is not packaged with the Libreoffice embedded python environment. Is there a way to add it?
Second try : inject embedded environment inside a precreated venv
What I did here was to create the Venv in pycharm using a standard python version aligned with the one libreoffice uses (here 3.8.10). Once the venv is succesfully created, I manually change the path to the python based interpretor to the proper libreoffice one.
I also update the pythonpath in pycharm for this venv to include Files\Libreoffice\program\ so that we can find some preinstalled modules suitable for Libreoffice, in particular uno.py.
This looks a little better, I can launch a libreoffice instance, but when I actually want to do stuff inside this instance from python, I get the following error loading component library </mergedlo.dll> failed
This mergedlo.dll file is in a directory referenced in the python path for this venv.
What configuration did I miss here?
I have just started working on my new pc and just to get a feel for it I wanted first to start working on python files, so I started first by just wanting to run WSL on windows and it installed correctly but when I want to run any python using the run python file on the top right on VS code, this is what gets executed $ C:/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe f:/Projects/hello.py
And this is the error: -bash: C:/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe: No such file or directory
I have no idea what's causing it but when I run the file using 'Shift + Enter' which is: Python: Run Selection/Line in Python Terminal it seems to run the single line correctly but it gives me this error instead:
print("Hello, world")
-bash: syntax error near unexpected token `"Hello, world"'
but when I run it using python3 hello.py, it works perfectly fine?! I'm so lost as to why this is happening and how could I fix it.
Might be relevant: I'm using windows 10, installed python 3.10.2 from windows store, all of that is in VS code and the python code is one line: print("Hello, world") and I changed the permissions of Local/Microsoft/WindowsApps so it's now accessible by all users to view/read/edit/run, made sure that python3.10.exe exists(on the WindowsApps and it works perfectly) and reinstalled it many times, tired python3.9, and tried to install python from the website instead of the windows store and still the same, manually added python to PATH and tried .venv and didn't work. when I launch python3.10.exe outside vs code it seems to run perfectly, I have worked with python before and it used to work fine now I don't know what's wrong.
I have seen other questions of the same problem I'm having here but none of them solve the problem.
No such file or directory C:/Users/...
For wsl, the Windows filesystem is accessible, but it has a different path. It is mounted under the /mnt folder. So you would find your python .exe under /mnt/c/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe. This said, the executable file is meant to work on Windows, and it doesn't really makes sense to use it on Linux when you could run python within your wsl distro.
python3 works perfectly fine
This is because most Linux distributions come with python3 pre-installed, so you can use it already. To see where it is located, you can run the command which python3, or python3 --version to check its version.
If you want to change version, you may consider download it from you package manager, apt.
I also suggest to install python3-pip if you don't have it already to get the pip package manager for python.
In my case when I ran into this.. I discovered pyenv. This allows you to download more than one version of python. You can then go into a specific directory, such as your python project and issue a python local 3.10.0 (for example). Here's a link on how to install it as well as poetry which is a virtual environment manager that is become very popular. You can also create an alias for python that works off of this. I add this command to my alias file and source it from my .bashrc. alias python='pyenv exec python3'
I was trying to run a Python script via Mac's Automator and the command is very straight forward:
"cd /Users/myname/Desktop/project && python3 myprojectapp.py".
However, every time I tried to run it, Automator raised an error such as ModuleNotFoundError. This was however, impossible since I had all libraries (e.g. Pandas) installed and running the command in the Terminal as written above worked flawlessly.
Now, I've read somewhere for a similar problem to just include:
"export PATH=/usr/local/bin:$PATH" before the command and it worked. Now, before I go on with my life, I would like to understand what exactly this extra line does and how it affects Automator to the point of making the script work.
Thank you in advance!
That command basically modifies the environment variable PATH and puts the directory /usr/local/bin before everything that is currently in PATH. However, that command is temporary, and the environment variable PATH is restored when the session closes.
What could be happening is the python you're running in terminal and the python Automator is running are different./usr/local/bin probably contains the same python version as you are using in terminal. Take a look at ~/.bash_profile to see if something similar to export PATH=/usr/local/bin:$PATH is in there.
Another way to check is to type which python in both and see if it points to the same python. You probably have yet another python somewhere in the list of directories in your PATH variable.
It's common to use virtual python environments to keep track of which python is running and to experiment with python without messing with system python. Examples of these include: Anaconda and virtualenv.
I have successfully installed z3 on a remote server where I am not root. when I try to run my python code I get :
ModuleNotFoundError: No module named 'z3'
I understand that I have to add it to PYTHONPATH in order to work and so I went ahead and done that like this:
export PYTHONPATH=$HOME/usr/lib/python-2.7/site-packages:$PYTHONPATH
I still get the same issue though, how can I verify that it was correctly added to the variables environment? what am i doing wrong?
Did you pass the --python flag when you called scripts/mk_make.py?
See the instructions on https://github.com/Z3Prover/z3/blob/master/README.md on how to exactly enable Python (about all the way down in that page). Here's an example invocation:
python scripts/mk_make.py --prefix=/home/leo --python --pypkgdir=/home/leo/lib/python-2.7/site-packages
Change the directories appropriately, of course.
For Windows users that just downloaded and unzipped the compiled Z3 binary into some arbitrary directory, adding the location of the python directory in the directory where Z3 was installed to PYTHONPATH did the trick. ie in Cygwin : $ export PYTHONPATH=<location of z3>/bin/python:$PYTHONPATH (or the equivalent in a Windows command shell)
I have a working Python project on my PC, which I am running from Pycharm.
It uses Pyroot (an interface to Root C++ library), whose C++ lib path I have added in Project Settings/Python Interpreter/Paths in Pycharm. It also needs to use the 2.7 Python interpreter, instead of 3., which is a default python in my terminal.
I want to run this project remotely on another desktop, so I need to be able to run it from terminal specifying the path to Root and the interpreter version.
Is there a way to easily extract from Pycharm the exact run command it is using when I'm running the code via run button?
Alternatively, if that's impossible, how should I specify the path to Root and the interpreter version when running from terminal?
I guess to best way is to create a virtualenv either in the terminal or in pycharm including the corrext python version 2.7 and install pyroot via pip into this virtualenv. Then you can simply ssh in the remote host, activate the venv and start your project from the terminal. Or you ssh into it with X-forwarding and start Pycharm itself from your client.
If you select the correct project and go to File > Settings, under the Project Settings you can see the Project Interpreter which tells you which interpreter is being used.
Hope this is what you are looking for.