running pycharm using python.exe instead of pythonw.exe - python

I am trying to debug some scripts for LibreOffice (which has a customized python interpreter). Is it possible to configure Pycharm to only use python.exe as pythonw.exe does not exist for this application?

Related

Run a Python script using Spyder from a Windows batch file

On a Windows machine, where I have no admin rights, I've created a python script which loads a module that is only available in Spyder development environment. To run it, I have to open Spyder, select the script and the working directory, before actually running the program.
I'd like to automate those steps. The ideal way would be to run the script from a console (in the correct directory), loading the python modules available in spyder.
Something like:
spyder.exe myPythonScript.py
Any idea about how to do it?

Module import errors with Virtual Environments and VSCode

I have created a virtual environment to install some Python modules. I am using mini-conda to manage and activate the environments.
One issue that I am facing is that the code runs fine when I run it through the terminal with the virtual environment activated.
However, the same code does not run when I use the "Run Code" button (Ctrl + Alt + N) in VSCode. It gives me Module Not Found Error.
How can I run the code from VSCode in the context of my virtual environment?
You should use the same interpreter in VSCode;
To do this you should use Python: Select Interpreter option;
CTRL+Shift+p(default key-bindings) and search for Python: Select Interpreter or search for it in the VSCode settings.
You must have the Code Runner extension installed because the Run Code option is provided by the Code Runner extension.
The triangle button for running code in the upper right corner has three options, among which Run Code is the way to run code provided by the Code Runner extension, while Run Python File and Debug Python File are the way to run and debug code provided by Microsoft's official extension Python.
Running the code with the Run Code option will run the code with the Code Runner extension. And Code Runner does not change the interpreter as you select a different interpreter in the Select Interpreter panel. It seems to always use the preferred interpreter from the system environment variables.
So although you are in a virtual environment and have some packages installed. But when you run code with Run Code, the interpreter is not the virtual environment of your choice. Although you have selected the virtual environment interpreter in the selection panel, this is only valid for Run Python File and Debug Python File provided by the Python extension.
So, run the code with the Run Python File option provided by the Python extension. Or install the packages you need for the interpreter environment currently used by Code Runner.
You can check the currently used interpreter with the following code
import sys
print(sys.executable)

Unable to execute Powershell from vscode because it somehow runs in Python debug mode

I try to run a powershell script from vscode (pressing F5 to execute it), but it fails because somehow the terminal concatenates the python path and python debug launcer along with the powershell path. How do I solve so that when running a Python scripts it takes the python path, and when running powershell it automatically runs powershell?
When running (F5) the powershell script from vscode the following path is interpreted by the terminal:
PS C:\Users\luuk\Desktop\Scripts\Archive\Archive> & 'C:\Users\luuk\AppData\Local\Programs\Python\Python38\python.exe' 'c:\Users\luuk\.vscode\extensions\ms-python.python-2020.11.371526539\pythonFiles\lib\python\debugpy\launcher' '60329' '--' 'c:\Users\luuk\Desktop\Scripts\Archive\Archive\Powershell\StreamingSQLToPBI.ps1'
What do I need to change so vscode automatically detects only the Powershell path?
Solution: To execute PowerShell script in VSCode, in addition to installing the extension "PowerShell", we need to open the terminal "PowerShell Integrated Console": (F1, PowerShell: Restart Current Session), then select the code, and click F8 to execute the code in this terminal.
The reason for these paths is that in VSCode, when we click F5 to debug the file, VSCode is executed in the "Python Debug Console" by default. It will specify the Python interpreter used for the terminal and the Python extension used (Python extension provides Python debugging function), the path of the script to be executed.

I need to set up an python interpreter when i clone a repo on pycharm

when I clone a github repository to my pycharm it says that I don't have any python interpreters for that project, but when I open the terminal (pycharm terminal) and type "python name_of_the_file.py" it runs the program without problems. Do I have to set up a python interpreter for the project or not?
ps: pycharm doesn't give any kind of error when I import some module for that project (bult-in module and not bult-in modules)
You just need to tell PyCharm where your Python interpreter is. Go to File -> Project Structure -> Project and select a Project SDK. I suggest creating a new virtual environment for each project.
Opening the terminal and typing python uses the system's PATH variable to find the executable. PyCharm doesn't use this automatically and you have to set it up.

Connect Ipython Notebook to PyCharm Python console

PyCharm 4.5.4 has an option "Python Console" (Tools -> Python Console) which runs a Python interpreter with proper paths and allows to debug Django projects (for example). Aslo it has an option of using IPython if it is present, and the question is if it is possible to connect an IPython Notebook or QtConsole to this interpreter?
I've tried using %connect_info and %qtconsole, but it doesn't work, probably that means that the kernel is not running (like if I were to run just $ ipython). If so can it be started without a lot of trouble?
Turned out to be easier than I thought.
So, in order to use IPython Notebook to debug local Django App in the Django Console, you need to add django-extensions library to your project's interpreter, append it to settings.py INSTALLED_APPS, then go to the "Terminal" tab in PyCharm (its options are in Settings -> Tools -> Terminal), navigate to the folder with manage.py if you are not there, and use a command
python manage.py shell_plus --notebook

Categories