VS Code - can you display a Python shell [duplicate] - python

This question already has answers here:
How to execute Python code from within Visual Studio Code
(34 answers)
Closed 4 years ago.
When using Python IDLE I find the Python shell, with the >>> prompt very useful for testing syntax. Is there a way of getting a Python shell integrated in VS Code?
Maybe the answer is just to open Python IDLE in another window.
Apparently this is a duplicate of another question, but I did several searches on the words Python shell and didn't find anything that seemed relevant. Sorry.
Many thanks to Jaxi for the answer that you need to type Python in the Terminal Window.

stated here you can use ctrl+backtick to open a terminal window, then from there just type python and it will give you the python shell:
https://code.visualstudio.com/docs/editor/integrated-terminal

Related

SyntaxError when pasting multiple lines in Python [duplicate]

This question already has an answer here:
Pasting multiple lines in MacOs Python shell returns SyntaxError
(1 answer)
Closed 1 year ago.
I'm having trouble copy-pasting code in Python. Say I have the following code I want to paste into a Python interpreter:
string_one = "Help"
string_two = "Me"
Locally, running 3.8.5 on a Mac OSX 10.15.7, if I paste that code, I get SyntaxError: multiple statements found while compiling a single statement.
However, if I ssh into another machine, open up Python (3.7.4), and paste those two lines, I get no error. Also, when I paste those two lines into a Python 2.7.16 shell, I get no error. What could possibly be the problem here?
Python 3 (problem shell)
Python 2 (non-problem shell)
It seems that there is a bug in readline (which is used by Homebrew to install python)
Short answer:
echo "set enable-bracketed-paste off" >> ~/.inputrc
Long answer:
https://github.com/Homebrew/homebrew-core/issues/68193
(This was erroneously edited into the question; I have rolled back that edit, and am pasting the solution as an actual answer instead, and tagging as Community Wiki.)

How do I input data into a command prompt from within python 2.7 [duplicate]

This question already has answers here:
Running windows shell commands with python
(7 answers)
Closed 4 years ago.
I want to open a cmd and then input data into the command line from python. I plan to call PEST calibration software to open from within python and I want to start by opening a cmd.
I am using Python 2.7 and so subprocess doesn't seem to work. I have tried os.system('cmd') and I can open the prompt but I can't input any data.
import os
os.system('cmd')
You should be able to pass the exact resulting string to os.system(). Ex:
os.system('notepad.exe')
In other words, os.system behaves the same way a console would.

Python3.6 on Windows MINGW64 console doesn't run the interpreter [duplicate]

This question already has answers here:
Python not working in the command line of git bash
(20 answers)
Closed 5 years ago.
I'm experiencing the same issue as this question with Python 3.6. It works well under the Windows console, but it fails to launch or work under MINGW64. Even when I use the direct path of /c/Python36/python.exe, nothing happens. I don't get the interactive REPL with the usual Python interpreter version and >>> prompt, as I do in the Windows console.
Any pointers on how to debug this?
Ah - further search yielded this stackoverflow question that contained the answer - use python -i

Problems running Python in Notepad++ [duplicate]

This question already has answers here:
How do you run a python script from within notepad++? [duplicate]
(6 answers)
Closed 7 years ago.
I'm having trouble executing my programs in Notepad++. I'm currently operating on Windows 7.
When attempting to run the program in the the interpreter, I have to jump through numerous hoops to actually get my program to execute. In Notepad++, I'm unable to provide additional text if I'd like to run a sys.argv command, or need to write in a name for a function.
Are there any solutions? Any easier way to run my code?
Run your code from command interpreter.It will look like this
C:\Python27\python.exe programe_name.py
change directory where your program is save before the command.I recommend you to download IDLE editor.It is easy way to learn python.
What I have been doing is this:
Press F5 to run.
Paste this | C:\Python27\python.exe "$(FULL_CURRENT_PATH)"
Replace Python27 with whatever version you use.
Then run.
It should take what you're writing and run it, make sure to select Python as the current language too.
Sorry if this isn't what you're looking for, I'm just starting too!
There are better editors which can run python without a problem. Github's atom can do this easily and is a great free solution and Sublime Text 2 is also both free and paid.
However, if you absolutely have to run on NotePad++, do click Run on the Menu and then Run again. Now, type in the shell command you would like to run (Path-to-python.exe + Path-To-File) and click run

Is it possible to make python into an executable file? [duplicate]

This question already has answers here:
Create a single executable from a Python project [closed]
(3 answers)
Closed 9 years ago.
Is there a way to make python an executable file on a mac, windows, or unix?
Nothing fancy in a GUI, but open a terminal window or a console window and run like somebody executed the application through terminal.
If there's no easy way to do this, can someone direct me to any reading material? Thank you!
You can use PyInstaller (http://www.pyinstaller.org/), there is also py2exe (http://www.py2exe.org/).
My experiences with PyInstaller on Linux show that it tends to place a lot of shared libs which may sometimes clash with your distribution so it's sometimes necessary to trim it down a bit afterwards.

Categories

Resources