Today just for practice I have downloaded and installed vscode.
I saw a tutorial on the installation of vscode for python and followed the procedure exactly.
But upon completion, whenever any python code is running, it is throwing an exception.
Eg:- A simple code I was trying to run like
def greet():
print 'Hello world'
But the terminal is throwing an exception saying "Invalid Syntax"
I really don't know where I am going wrong
If anyone of you has experience working on vscode and is willing to help then please tell me what I can do
The extensions I have enabled:-
Code Runner,
Python
Earlier the python extension was not enabled, but even after enabling it, the error is still there
Please have a look at the problem I am facing in setting things up with vscode
You should not type in python in the terminal.
Because the Python Extension only sends some commands to the terminal and then executes them.
If you type python in the terminal you will enter into the interactive mode, and the commands which intended to be executed in the terminal will be executed in the python interactive mode, and lead to SyntaxError.
So, you can get out of the python interactive mode through Ctrl+Z shortcut or kill the terminal and then execute the commands in a new terminal.
Related
I'm new to Python (3.10.4). I've been reading Mark Lutz's textbook and I'm only getting comfortable with the environment (Windows 10), and all this time I've been under the impression there's no real difference between running Python programs in cmd or powershell. However, today I followed the suggestion from the textbook and tried launching a Python script file without typing "python" at the start of the command line, and PowerShell returned me an error message saying "[the script file name] could not be identified as a Cmdlet, a function, a scriptfile or a executeable program." At first I thought I was doing something wrong, but then I tried doing the same in cmd, and I got the expected output. So, in cmd this syntax works just fine.
Then I noticed the PowerShell suggestion that was printed out below the error message. It said if I trust the command, I should run it with a different syntax, so not like
filename.py
but like
.\filename.py
I tried doing this, and it launched the file (a tiny black window blinked as if I double clicked the file), but I didn't get the output in the PowerShell window this time either.
So, my question is: what's the difference between cmd and powershell from the Python perspective? Why do they treat Python differently? And as I study Python, should I stick to cmd rather than to PowerShell from now on?
I'm kind of new to software development. Outside of VSCode, I can open up a terminal (let's say PowerShell), run python in it, type in a command (like 2+2), be able to click the up arrow key to find my previous command so that I can run it again.
If I run PowerShell in VSCode and do the same thing, nothing happens when I click the up arrow where I would expect my previous command to be cycled.
Is this a problem with my Python or VSCode? I've been looking for a solution for this but haven't found many useful topics on this.
This was going to just be a comment but its too long. Sorry it isn't more informative than it is. This is kind of an odd problem because VSCode isn't a true IDE. It doesn't have its own shell and just hijacks your powershell or bash terminal, depending on which OS you are using. You should be able to use your up and down arrows just like you can in powershell. I have tested it on my own VSCode installation and it works fine for me. If it's a problem, it's not with python, since VSCode will interact with the terminal the same way no matter which language you are using it for, so its probably with VSCode or your terminal. I have heard of others having issues with up arrow autocomplete in bash, so if you are connecting to a bash terminal that could be it, but I've never heard of it glitching in powershell. I'd say check which terminal you are using, see if the problem persists when you change terminals, and try reinstalling VSCode if it does. Past that, I don't know what to tell you.
I found a work-around. For me, neither git bash, nor PowerShell allowed up/down arrows for history switching within a python shell. So here it goes.
Ctr-Shift-P opens VSCode commands
Python: Create Terminal does not actuallt start python, but it does launch powershell in a mode that will enable us to succeed
py starts python shell with working up/down arrows!
It seems that the spyder has removed python console, but I got a program can only be run by python console, what can I do? or is there any thing I am wrong?
I got some codes from github, and it needs ADB driver for Android, after I installed ADB, I can run the program in cmd using python wechat_jump_auto.py, but cannot run in spyder with ipython.
In Spyder3 installed in Windows OS, we can add the path to adb using Tools --> Current user environment variables....
Here, we can add the path to adb.exe file by appending it to the path variable. Then, we need to restart Spyder3. Then you will be able to directly run your script with access to adb.exe from Spyder3 IPython console or simply by clicking Run button.
Just came across the same problem as you recently.
In fact, it seems that program using ADB tools just cannot run in Spyder even by python console (my Spyder IDE is equipped with both Ipython console and Python console).
One practical way to solve this problem is to run your code in cmd.
Open your cmd window and do something like this:
python "xxx(path)\xxxx.py(file name)"
In my case, it looks like this:
example image
Hit Enter, and hopefully your code will run successfully.
If it still cannot run, maybe you haven't set your environment variables correctly.
Hope this can solve your problem. Good luck :)
I'm trying to use emacs as my python develloping environement. But I'm facing a problem.
All communication between emacs and any python interactive shell that is called by python-shell seems broken:
The shell seems to start normally, displaying versions and giving me a prompt but then as I enter commands, nothing seems to happen. I have no answer from the interpreter. I can keep writing things but they then stay there in the middle of the screen and nothing happens. I've tried setting regular python interpreter to python and ipython and nothing changes.
I also try to invoke a system shell, that works correctly, and then call python or ipython from there, that brings me back to the same "no response" situation. It just looks like a normal buffer that I can edit. I can delete through the prompt, write some character anywhere in the screen, in the version info... It doesn't looks interactive at all.
What could be the reason of this problem?
I normally program in Java, but started learning Python for a course I'm taking.
I couldn't really start the first exercise because the command
python count_freqs.py gene.train > gene.counts
didn't work, I keep getting "incorrect syntax" messages. I tried solving this looking at dozens of forums but nothing works, and I'm going crazy.
import count_freqs
ran without errors, but I can't do anything with it. When I try running something involving the file gene.train I get "gene is not defined".
Can anyone tell me what I'm doing wrong? Thanks.
type which python at the command prompt to see if the python executable is in your path. If not it either isn't installed or you need to amend your path to include it.
on Windows you can type echo %%PATH%% at the command prompt. It will give you at list of all the directories the shell search for programs to run. By default Python 3.3 will be installed on C:\Python33.