Basic File Won't Run -> Unable to initialize device PRN - python

I am very new to Python, and have recently switched to VS Code from Jupyter Notebooks, and am trying to run some simple code but am getting an error.
I've looked around for the solution already, and I can find the same error message but nothing matches my issue.
I'm just doing very basic code:
msg = 'Hello World'
print('msg')
The error message I get is in the terminal and looks like this:
(base) C:\Projects\Python\Tutorial>print(msg)
Unable to initialize device PRN

As rayryeng said you need to run your code in a Python environment.
If you are using VS code there is Python REPL where you can run your code interactively. To activate it you can press Ctrl+Shift+P and type/find Python: Start REPL after that you will see terminal panel at the bottom of VS Code as on screenshot:
Sure, you need VS Code Python extension and Python itself installed in your system.
Alternatively you can run Python shell directly from your command line by typing python or python2/python3 depending on your installed version. Python must be in the PATH variable

Related

Unable to set up vscode to practice python

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.

VS Code trying to run .../Activat.ps1 in cmd terminal

I'm using VS Code for a Python project using a virtualenv. I switched my deafult terminal from powershell to cmd as VS Code was not happy executing powershell scripts.
Now when I open a terminal in my project it opens cmd (as desired), but automatically tries tor run .../Scripts/Activate.ps1, which it doesn't like. I want it to run .../Scripts/Activate.bat as we are in cmd. Runnning it manually for now, but would be nice if I didn't have to.
No doubt there is a setting somewhere to change this, but I cannot find it. Any ideas?
This is a problem related to the Python extension, it should be fixed in the last update.
You can get some information from here.

I am unable to run any command or file of python - there is no output in terminal

Whenever I try to run my python code or even the simplest hellow command in VS Code's termilnal, it is just showing this:
C"/users/admin/document/my python file
Why does it happen?
Oh, this is more like an VS-Code question. But anyways: I believe you have to use a command to run the file, just like this:
py <file-path-here>
Example:
py example.py
Also, maybe try installing the Python extension in VSCode.
And make sure you have Python installed correctly (check the button "add Python to path" in the first page of the Python installation setup).
If all of this does not work, make sure to select the correct Python version in VSCode by doing this:
Go to top menu, click view, command pallete, type Python Select Interpreter and choose the correct version.
Also, check if the file ends with .py so VSCode knows that you are working with a Python file.
Since you're new here: you can support me a lot by upvoting this answer or marking this as an answer. <3 Thanls

how to execute python script on atom on windows

I am using Atom on Windows 10. While setting up Atom on my computer, I created a folder called "beyond basics". Then I created a python file. I installed platform io on Atom. i got a "+" icon on screen. upon clicking that i got a command line. I am trying to execute on that by writing python filename but I am getting an error. Any help is appreciated.
python3 myfile.py
Try typing myfile.py without the python prefix. It may work, as it works for me on Windows 10. Your bubble is covering up an error message that could help use debug. Can you add an edit and tell us the error message? Until then, just try the command without the python prefix.
You should also save before running, as was commented by Denis Fetinin.
If it still doesn't work, try addding python to the env variables. It's a simple process that you can follow here.

what can I do if a program can be run by python console while can not be run by ipython console?

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 :)

Categories

Resources