I have used the regular IDLE python interpreter. Now I discovered PyCharm. It's a really good formatter and has a object hierarchy which I really like and auto-complete.
Unfortunately, PyCharm doesn't have the same interpreter as the regular python IDLE and I can't seem to get it to run w/ the regular python interpreter (Y'know, the one with the rocket in the icon?) and I can't seem to figure out how to get that same interpreter running
If you can give me any suggestions on how to get PyCharm to run on the regular interpreter, that would be nice, as I'm making a text based game, and the Pycharm console isn't great for those.
I've already tried looking into changing the pycharm interpreter (the rocketship python wasn't there) and the pycharm website didn't have exactly what i wanted
Basically, I want to only use PyCharm as a python formatter, and use the regular Python IDLE as a interpreter
Selecting Interpreter in Pycharm can be done by going to:
Settings -> Project -> Project interpreter
In the project interpreter dropdown, you can find interpreters you used in different Pycharm projects(if any).
If not then you can add them from the little + sign at the bottom go to the required new or existing environment and select the location of the base interpreter/ interpreter where you interpreter is saved in the file system.
As John Anderson's comment said, You can configure python interpreter by File->Settings->Progject->Project Interpreter, you said it didn't have you wanted so you must add interpreter by hand. click the setting button, and Add a python interpreter.Generally python interpreter located in C:\Users\\AppData\Local\Programs\python\python37\python.exe.
Related
I want to run my Python project on my globally installed Python interpreter.
I don't want to be in the "Mosh Python Standard Library" virtual environment anymore but I can't figure out how to exit it.
This what is shown in my output window in VS Code:
Here is a picture of my VS code terminal, the venv doesn't appear to be active:
Sorry for any confusion in my post, I am new to programming.
You can go to the vs-code's command pallet and type in Python: Selected Interpreter. This will open a window which you can choose which interpreter you want your python files to debug. Or you can click on the bottom left corner's button and it will do the same.
It turns out my default python interpreter in settings.json was pointing to the virtual environment, so even though I selected the global interpreter in the bottom left it would still run on the unwanted venv
I want to update the selected python interpreter inside vs code from a script.
I tried:
.vscode/settings.json in the workspace allows setting python.defaultInterpreterPath but it works only once. Even if select "default interpreter" in the UI (e.g. python 3.8), close vs code, change the setting to 3.9, open vscode again, vs code remembers 3.8.
$config_path/User/workspaceStorage/.../state.vscdb also contains a key ms-python.python which got data for the selected interpreter autoSelectedWorkspacePythonInterpreter - but that does not even change when changing the interpreter in vscode (from the name of the setting that kind of makes sense)
Where does vs code even store the information which interpreter is selected by hand?
Any pointers welcome how to change the used python interpreter (preferable from a script running outsideof vs code, but I would also write a vs code extention if that is easier :))
$config_path/User/globalStorage/.../state.vscdb --> ms-python.python.
I have been searching for this but after 2 hours I gave up.
I wanted to work dynamically with another IDE to run maya scripts using Python. So I downloaded Eclipse and I installed some plugins: EclipseMayaEditor (to connect Eclipse with the script editor in Maya) and PyDev (so that I can use the python interpreter in Eclipse).
It works perfectly fine, I can connect the IDE with maya and jump from one to another. BUT I miss a feature I had in Maya's script editor...
Eclipse is not highlighting me the maya commands such as xform, polySphere, and so on... It is not a big problem but it hurts my eyes a little bit when I stay some hours staring at the screen...
Is there any way to highlight the maya commands or maya nodes or whatever they are called (pardon me for my lack of technical vocabulary)
Thank you very much.
I haven't tried this myself, but the Eclipse Maya Editor plugin looks promising. Have you tried it? From the description:
This is a plugin for Eclipse that turns it into a Maya IDE. As it is
Python-centric, it also requires the pyDev plugin. Features include:
Send the entire contents of an editor to Maya
Send a highlighted selection to Maya
Python and mel scripts supported
Anything done within Maya's own script editor is also echoed in the console view
Change the port number of the socket at any time
Open up documentation for Maya's Python API, Python Commands, Pymel, Qt, PySide, PyQt and User options
Get results back from Maya in it's own console view
Eclipse Helios, Eclipse Indigo and Eclipse Juno supported. Requires PyDev plugin.
Reading further though, it looks like it may not do highlighting. From a feature request listed as "pending":
Color highlighting on maya python commands
Only maya mel commands get colored, but not maya python commands. The
default python functions get highlighted, but not maya’s python
commands. I find it useful to avoid typos...
It's possible that request is out of date and it's been implemented since then. You'll have to try it yourself to know for sure. Let us know!
This article walks through the steps for getting autocomplete working. While it's not as nice as full syntax highlighting it does give you automatic expansion of function names, fields and methods in Eclipse.
Basically you want to make sure that your interpreter knows the location of the maya python directories and the pypredef folder inside your maya install. Here's shots of my setup. This is the Libraries tab of my Maya python interpreter:
and here's the prefedined tab:
Your paths will of course be relative to where your maya is installed but this should be enough to enable autocomplete. You'll be able to customize the color scheme in the preferences > themes setting, but I don't know of a way to call out specific imports from other modules in the way the maya editor does.
I'm new to python and pycharm and I'd like to run a module from the pycharm console in the same way as you can from IDLE, if it's possible.
The idea is to create simple functions and test them "live" using the console.
...how do you do that in pycharm?
Running python scripts using pycharm is pretty straightforward, quote from docs:
To run a script with a temporary run/debug configuration Open the
desired script in the editor, or select it in the Project tool window.
Choose Run on the context menu, or press Ctrl+Shift+F10. So
doing, a temporary run/debug configuration is created on-the-fly.
Besides there is a "Python Console" available in pycharm: see documentation.
UPD:
Here's an example.
Imagine you have a python module called test_module.py:
def a(*args, **kwargs):
print "I'm function a"
def b(*args, **kwargs):
print "I'm function b"
Then, in pycharm's "Python Console" you can do this:
>>> from test_module import *
>>> a()
I'm function a
>>> b()
I'm function b
If you need to execute a part of an existing code, you can use the Execute Selection in Console feature: select the code snippet -> right click -> "Execute Selection in Console".
For anyone still having this problem: Go to the Run/Debug menu, choose Edit Configuration, check the box 'Show command line' this will enable you to enter parameters in the console at the >>> prompt and test your function.
Edit: To make this change apply to all your .py files (as this check box only applies to the current file you're working on) go to: Edit configuration, in the pop up you will see a menu tree on the left, select Defaults, then Python, then check the 'Show command line' box, this will make it the default setting whenever you open a .py file, (this feature should really be on by default!)
Right Click --> Run File In Console
Done!
Looks like in version 2018.3, this option is now Run with Python console in Run/Debug Configurations:
What you're looking for is the feature called Execute Selection in Console which is described in section Loading Code from Editor Into Console of PyCharm's online help.
Select the script lines that you want to execute and press Shift+Alt+E
You can run the Find Action shortcut (Ctrl+Shift+A or ⌘+⇧+A on mac), then type run file, and choose the option Run file in Console.
In pycharm do:
Run>Edit Configuration>Show command line afterwards
Assuming your code is in file MySimpleCode.py you can simply say
run MySimpleCode
in the PyCharm console. This assumes that you have set your working directory properly; e.g. if MySimpleCode.py is located in d:\work on a Windows system you must execute
cd d:\work
first. In my opinion the other solutions miss what the post really wants: simply executing a file like from a DOS or Unix shell, or a .m script in MATLAB. No messing with imports, projects and so on. If you use CTRL SHIFT F10 your code gets executed, sure, but in a different environment, so you have no access to variables created in your code. I assume the question means that you want to do further work with the results of the script.
Explanation for people with MATLAB background: In most Python IDEs you have to configure an interpreter first in some kind of project. The MATLAB equivalent would be a master IDE where you can choose your MATLAB version for each project. This makes it possible to run your Python code on the CPU, your GPU or even an external NVIDIA board with different settings (after several days in the installation hell). For the beginner this is very confusing, because for simple code samples any "default" interpreter should suffice. Unfortunately this is not the case for Python (2 or 3? 2.x or 2.y? which package version?), and it will get worse as you progress (which 32 or 64 bit version of TensorFlow is available for Python 3.x? and so on).
TextMate seems to use the built-in Python version I assume (sys.path doesn't work). How do you configure it to use 3.1 instead? I've already installed the 3.1 package and I can use IDLE for interactive sessions, but I need to use TextMate now.
Thanks
TextMate uses the value of the TM_PYTHON variable to find the path to the Python interpreter. A good solution is to take advantage of TextMate's ability to define variables like TM_PYTHON on a per-project basis:
Open a new or existing TextMate Project (File -> New Project or File -> Open)
De-select any file in the project list sidebar.
Click on the Get Info (i) icon in the sidebar. A Project Information pane appears.
Click + to add a new variable.
Enter TM_PYTHON in the Variable field and the full path to the desired python in the Value field (for example, /usr/local/bin/python3.1).
Close the Information window and save the Project (File -> Save Project As).
Then you can add files as needed to the project and they will be run under the chosen python with TextMate Python bundle's Run Script command. You might want to save a Python 3 project, say, for running ad-hoc scripts under Python 3. For bigger projects, you'll want to create a separate TextMate project for it anyway.
To change the Python version used globally within TextMate:
From the TextMate menu bar, open TextMate -> Preferences
click on the Advanced pane
click on the Shell Variable tab
click the + to add a new variable
enter TM_PYTHON in the Variable field and the full path to the python in the Value field (perhaps /usr/local/bin/python3.1)
As Alex points out, you may break other TextMate functionality by changing the Python version globally so the per-project change is probably a better solution.
UPDATE (2010-10-31):
There is another approach that may be easier to use for some projects. The Run command in TextMate's Python bundle appears to respect a shebang line in the file being run. So, instead of modifying TM_PYTHON, you can specify the path to the interpreter to be used by including a first line like this:
#!/usr/local/bin/python3.1
# sample code to show version
import sys
print(sys.version_info)
In many case you would prefer not to hardwire the absolute path but manage use through the normal shell PATH environment variable. Traditionally /usr/bin/env is used for that purpose. However when running under TextMate, your shell profile files are not normally used so any changes to PATH do not show up there including possibly /usr/local/bin or /opt/local/bin or wherever your desired python3 command is located. To get around that, you can add or modify a global PATH shell variable to TextMate -> Preferences (see above) with a value of, say, /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin. Then you can use a more general shebang line like this:
#!/usr/bin/env python3
(This all seems to work with the most recent vanilla TextMate and its Python bundle: no guarantees about earlier versions or with other Python bundles.)
Late to the party, sorry! I take it you want to run the script using TextMate's 'built-in' interpreter? I've found the simplest solution is to add a shebang, which works extremely well;
#!/usr/bin/env python3
for python 3.1 or;
#!/usr/bin/env python
for default system python, although the latter is superfluous for the exercise.
According to this long thread (which was about Python 3.0, and the TextMate version existing back last spring, but I believe is still valid for Python 3.1 and today's TextMate), you can get it done (e.g. via #Ned's answer), but once you do many TextMate commands may well break (because they're written to use Python 2, and Python 3 is not backwards compatible with Python 2 -- for example, the use of reload, which disappeared in Python 3, is repeatedly mentioned in the thread). Still, it might work if you do not use or need much of TextMate's functionality (LaTeX typesetting for example was mentioned as something that totally breaks once you make TextMate use Python 3 instead of Python 2).
the shebang is the best solution, to see where python 3 is installed type in terminal:
which python3
you will get something like this:
/usr/local/bin/python3
if nothing shows up first install python3
and at the top of your script insert:
#!/usr/local/bin/python3
I wanted to achieve this in TextMate version 2.0.23 with the aim to use python3 as the default.
So this is how I could set the TM_PYTHON variable (based on #Ned Deily's answer above):
Open Textmate
Hit CMD + ; to open the settings
Now Add a new Variable with the + sign
4. In the Terminal.app I typed which python3 which gave me /usr/local/bin/python3.
Now whenever I open a python script and hit CMD + R it will execute as a pyhton3 script by default while "honouring" the installed PIP packages.