How to specify non-standard Python interpreter? - python

My application has built-in Python interpreter and I need to debug Python code there. However Visual Studio Code allows to choose only from interpreters found in paths and named python/python2/python3.
I tried to set python.pythonPath in settings.json to point to my application, but Visual Studio Code doesn't recognize it as valid Python interpreter.
Sure, I need to make sure that my application behave like Python interpreter and pass all command-line parameters to Python ptvsd_launcher.py.

The "python.pythonPath" setting is how you can specify a Python interpreter that is not automatically detected. If the binary does not function as a normal python binary then unfortunately there's no way for the extension to use it.

Related

In VS Code API, how can one get the Python environment path?

When implementing a Visual Studio extension to be used with Python files in the VSCode editor, how can one programmatically get the path of currently selected Python environment?
My guess is that it is done with python.pythonPath, but I can't seem to make it work. If I use that directly within an extension js, it crashes. I also tried:
let python = vscode.extensions.getExtension('python');
python.pythonPath
python.pythonPath is a setting, so you can do this with VSCode's generic settings API (instead of having to rely on the Python extension exposing an API specifically for this):
vscode.workspace.getConfiguration("python").get("pythonPath")

Set paths for JetBrains PyCharm [Linux]

I run Python program which uses couple of source paths on runtime.
I put these rows on my /.bashrc file:
source home/raphael/kaldi/aspire/s5/cmd.sh
source home/raphael/kaldi/aspire/s5/path.sh
So when I'm running from terminal everything works fine and Python manage to locate paths.
However when I'm trying to run through PyCharm for DEBUG purposes mostly it seems that PyCharm can't locate the paths.
Is there anyway to add the paths manually for PyCharm or make it read /.bashrc file. What I am missing?
You can try using the options available in the Run/Debug Configuration settings (Run > Edit Configurations...)
You can set environment variables individually (such as $PATH), or at the bottom is a section to define external tools (scripts) to be run when your Python code is run or debugged. From that sub-section, you could set your bash scripts to be run each time you start debugging.
Alternatively, see if using os.environ would work for your project. Check the docs for more information.

Is it possible to compile python interpreter to static single exe (with eventual one dll or so) with most used packages?

I don't mean to compile code and interpreter as an exe as it is 99% questions there. I mean to build a static single python.exe to be able to execute any script by giving it as argument any *.py file.
I mean the same situation as it is with nodeJS when you download only single executable.
Or if it is not possible to single exe, maybe to just a few files instead of huge default package such as is with for example Sublime text where all python engine is in python33.dll and python3.3.zip all about 5mb, but there is no python exe to run code externally that is not as a plugin.
On Windows you need three files. You question lists two of them. The third is python.exe. On Windows the interpreter must be built separately from the actual executable so that C modules can access the functions within the interpreter.
The DLL must be built from the Python source so that all the C modules that come with Python can be built into it instead of being contained in the .pyd files that come with Python. The zip file is composed of all the Python modules in the standard library; see the zipimport documentation for more information about the import process.

Python Installation Location (Windows)

I need to find out if there is Python installed on the computer.
My specific issue is that I am distributing a program that comes with its own interpreter + standard library (the end-user may not have Python). In the installation, I am giving the option to use the user's own installed Python interpreter + library if they have it. However, I need the location of that. I can ask the user to find it manually, but I was hoping there was an automatic way.
Since my installer uses my included interpreter, sys.prefix refers to the included interpreter (I know this because I tried it out, I have Python 2.7 and 3.3 installed).
I also tried using subprocess.call: subprocess.call(['py', '-c', '"import sys; print sys.prefix"']) which would use the standard Python interpreter if there was one, but I'm not sure how to capture this output.
Thus, are there any other ways to find out if there is a default Python version installed on the user's computer and where?
Actually, in the light of my other answer, an even better way to find the Python installation directory would probably be to check the Windows registry, since the Python installer places some information there.
Take a look at this answer and this Python module.
Some users might have placed their local Python directory into the system's PATH environment variable and some might even have set the PYTHONPATH environment variable.
You could try the following:
import os
if "python" in os.environ["PATH"].lower():
# Confirm that the Python executable actually is there
if "PYTHONPATH" in os.environ.keys():
# Same as in the last if...
As for the subprocess.call(...), set the stdout parameter for something that passes for a file object, and afterwards just .read() the file object you gave to see the output from the call.

Auto-Completion for Panda3d in PyCharm

Does auto-completion for the Panda3d library working with PyCharm? It seems PyCharm cannot automatically create the Python skeletons for this library. I would also be happy if I could at least manually define those stubs in PyCharm.
Any ideas how to tell PyCharm what Python modules and classes are there in a "binary" library?
For me it worked just selecting in Settings > Project Interpreter the panda python interpreter (python.exe, not ppython.exe.).
If you wanna use ppython.exe you have to rename to something starting with "python" like pythonpanda.exe, since Pycharm only considers an interpreter something that starts with "python". Anyway, ppython and python are supposed to be the same.
EDIT
Another thing that can make it work, is using another python interpreter (the standard, virtualenv, whatever) and placing a path file in a folder within the PYTHONPATH.
In other words:
Create a text file named panda3d.pth
Write two lines
path\to\pandafolder
path\to\pandafolder\bin
Save it in the site-packages of your python interpreter
Configure Pycharm to use this interpreter

Categories