PyCharm asks for python interpreter every time project is loaded - python

Rather frustratingly, every time I load up an existing project or create a new one - it complains there is no interpreter selected and I have to provide the path to it.
There is nothing unusual about my python installation, it's sat in C:/Python27/ as you would expect. It always used to work, but the last few weeks something has changed.
I'm running Win7. PATH system variable points to C:/Python27/ as it ought to.
If I crack open commandline, the python command opens as it ought to.
Any ideas?

There is no Default Settings any more, It's called Preferences for New Projects in the newer versions of PyCharm (my version is 2018.3.3).
For that, go to :
File > Preferences for New Projects > Project Interpreter

Setting the IDE default interpreter fixed the problem, as Vadim mentioned. Found instructions on how to do that here.
File | Default Settings | Project Interpreter.
This configuration sets the default interpreter for the new projects,
note the Default Settings menu, it's not the same as File | Settings
which sets options for the current project.
Not entirely sure why the default was unset, but at least now I can set it back again. The project default setting was being forgotten as well which is curious, but a problem for another day.

You can easily do it by going to File > Setting for New Projects > Project Interpreter:

On Mac: File > Preferences for New Projects.

Related

Python Interpreter not showing anything in PyCharm

Issue
So, I've used PyCharm for quite a while and I know how to set environments, etc. For some reason, I can't seem to access the Python interpreters that I've got (see image).
When I open the same project in Clion I am able to run the files and I can see the interpreters.
Attempted solutions
Run in Clion to see if the interpreter "sticks".
Removed the .idea file.
Reinstalled PyCharm.
Usually Python Interpreter is a sub-item of Build, Execution, Deployment in the Settings. (In PyCharm 2021, the layout in PyCharm 2019 was slightly different).
The fact the item appears separately is a strong hint that you either installed a plugin or for some reason the IDE was opened in LigthEdit mode (this can easily happen if you launch the IDE using the command-line). This can also happen if you don't have an open project (having files open is not the same as opening a project, as such, with an .idea folder - the IDE configuration files will be different.)
Having the IDE in LightEdit mode provides only a limited set of functionalities, so the IDE doesn't allow you to configure an Interpreter in the usual way (other setting dialogues will also behave different from usual).
The solution is to Exit the LightEdit mode, opening your previous project or a new one by going to File > Open or File > New Project.

VSCode Python package inspection failure

This's probably quite off-topic but maybe someone else share my experience... when I started coding KiCAD plugins and learning Python I decided to use VSCode (with Microsoft Python extension) because I already use it for a number of other things and works great.
I have two main issues mostly bound to Python extension itself other than VSCode:
VSCode try to use python 3.7 binary (I installed it on my
machine and I need it) instead kicad/python 2 (it's installed on a different location);
even if I setup VSCode to look for additional packages with a specific configuration file (settings.json):
"python.autoComplete.extraPaths": ["C:/Program Files/KiCad/lib/python2.7/site-packages"]
VSCode refuse to investigate pcbnew.py (located in that folder) and thus every Intellisense like function (inspection etc) doesn't work.
How can I fix that? ... I'm more interested in fixing the second issue other than the first.
To correctly enable per project configuration of VSCode / Python open folder and create a workspace configuration for the project itself (i.e. create a .vscode folder inside project folder and store a settings.json file inside it with you custom configuration). In my specific case I needed to specifiy a custom location for an older Python binary trough python.pythonPath directive.

pycharm and subprocess - what works in console doesn't work in Pycharm

Pycharm's interpreter seems to have stopped understanding some of my console commands. It keeps recognizing default shell commands but doesn't recognize installed utilities.
For example, subprocess module understands touch command but doesn't understand heroku command.
The funny thing is, when I enter the same string into the console, with the same interpreter (from the same virtualenv), everything works fine.
A visual example:
It stopped working a couple days ago, and before that everything had worked fine.
I thought I had messed up some of my env vars, but opened an old project I hadn't touched for a month, and saw that the same subprocess commands stopped working there too.
What could be the problem?
UPDATE
Ok, I got this thing to work.
The values of os.environ['PATH'] were different in console and in Pycharm. After I added the correct PATH to the Pycharm configuration env vars, everything started working again.
Now the question is, how do I avoid going through each configuration in each and every of my projects and adding this new PATH everywhere? Is there a way to do this globally and repair this one only setting that's been broken?
I see you figured out how to configure PyCharm's project PATH.
As for how to not have to do this for every project new project you start, you just have to update your default project configuration.
From Accessing Default Settings:
PyCharm helps define settings of a default project. These settings
are used as defaults every time you create a new project.
To access default project settings
On the main menu, choose File | Default Settings
Define the desired settings in the Settings dialog box that opens.
Note: updates to the default project configurations only apply to future new projects, any existing project configuration needs to be updated manually.

#!/usr/bin/env python3.4 within PyCharm project [duplicate]

I have PyCharm 1.5.4 and have used the "Open Directory" option to open the contents of a folder in the IDE.
I have Python version 3.2 selected (it shows up under the "External Libraries" node).
How can I select another version of Python (that I already have installed on my machine) so that PyCharm uses that version instead?
File -> Settings
Preferences->Project Interpreter->Python Interpreters
If it's not listed add it.
I think you are saying that you have python2 and python3 installed and have added a reference to each version under Pycharm > Settings > Project Interpreter
What I think you are asking is how do you have some projects run with Python 2 and some projects running with Python 3.
If so, you can look under Run > Edit Configurations
PyCharm 2019.1+
There is a new feature called Interpreter in status bar (scroll down a little bit). This makes switching between python interpreters and seeing which version you’re using easier.
Enable status bar
In case you cannot see the status bar, you can easily activate it by running the Find Action command (Ctrl+Shift+A or ⌘+ ⇧+A on mac). Then type status bar and choose View: Status Bar to see it.
This can also happen in Intellij Ultimate, which has PyCharm integrated. The issue is as diagnosed above, you have the wrong interpreter selected.
The exact method to fix this for any given project is to go to Project Settings...Project and adjust the Project SDK. You can add a New Project SDK if you don't have Python 3 added by navigating to the python3 binary. This will fix the errors listed above. A shortcut to Project Settings is the blue checkerboard-type icon.
You can also add Python 3 as the default interpreter for Python projects. On OSX this is in File..Other Settings...Default Project Structure. There you can set the Project SDK which will now apply on each new project. It can be different on other platforms, but still similar.
Go to:
Files -> Settings -> Project -> *"Your Project Name"* -> Project Interpreter
There you can see which external libraries you have installed for python2 and which for python3.
Select the required python version according to your requirements.
Quick Answer:
File --> Setting
In left side in project section --> Project interpreter
Select desired Project interpreter
Apply + OK
[NOTE]:
Tested on Pycharm 2018 and 2017.

Eclipse and Pydev integration for Edx souce code

We are keen to use PyDev for our edX customizatoin and we want to configure edX code on it. Do you know of any documentation which talks about how to configure PyDev for edX code? Basically, I have imported all the projects of edX into PyDev but I am stuck at the point of building the projects as I am not aware of the configurations required to be done and there are lot of dependancies between various projects. Any help would be appreciated. Thanks & Regards,
Abhijeet Mote
I happen to know where to find the directions for configuring Eclipse.
You can find the details at the attachment of this post.
Edit: Update based on the configuration from the link
Create MITx python environment
Go to Windows>Preferences>PyDev>Interpreter - Python (Ubuntu) or Eclipse>Preferences>PyDev>Interpreter - Python (Mac)
Set up (or create new) location, pointing to ~/mitx_all/python/bin/python. You may need to spell out the home path. You may get a warning saying that source code is not found.
(If necessary, add /usr/bin/python2.7 to list of included paths for interpreter. That might provide some of the missing source code.)
Create MITx project
Do File>New>Other, select PyDev/PyDev Django Project
Enter "mitx" or similar as the project name and point to mitx_all/mitx location
In project properties (right click the project in left panel), set PyDev - PYTHONPATH, Source Folders to:
the root dir /mitx
/mitx/common/lib/xmodule
/mitx/cms
/mitx/cms/djangoapps
/mitx/lms
/mitx/lms/djangoapps
/mitx/lms/lib
/mitx/common/djangoapps
/mitx/common/lib
Create a manage.py file to use that's within the project hierarchy (instead of django_admin.py, which is over in mitx_all/python/bin). For example, put the following in ~/mitx_all/mitx/manage.py:
#!/home/<username>/mitx_all/python/bin/python
from django.core import management
if __name__ == "__main__":
management.execute_from_command_line()
Open Debug Configurations dialog. (Either right-click on project -> Debug as -> Debug Configurations or menu Run -> Debug Configurations to bring up configuration dialog.)
In dialog, right-click on PyDev Django -> New (New is the icon above the left nav).
On main tab, set name: pick a name to indicate what Django config you're using (e.g. LMS dev with runserver).
Project should be MITx (or whatever you called it)
For main module, browse to location of manage.py created above.
On Arguments tab, put program arguments. For example, to run the LMS, put "runserver --noreload --settings=lms.envs.dev --pythonpath=. 8000".
On Interpreter tab, select the MITx interpreter [which is in the drop down] (the one that uses mitx_all/python). This may be the same as your default interpreter, depending on your global interpreter settings.
In Environment tab, set DJANGO_SETTINGS_MODULE to point to the desired setting file (e.g. lms.envs.dev). If you aren't running with activate and such, then PATH may also need to be set (or augmented)

Categories

Resources