Why doesn't any python commands work in my command line? - python

I was normally using python3.7.3 on my system(Windows 10). A couple of days earlier I noticed that the command prompt won't run any of my python programs. It did nothing, no response. I thought there is a problem displaying the output stream so I ran an infinite loop(and was expecting to terminate the process, ctrl^c) but again no response. Even python --version command won't work. I uninstalled python3.7.3, downloaded the latest python3.8.5, and again the same problem. image from my cmd line
please help me out. I use sublime text so I prefer running my codes through cmd.
Update: Here is another snap of my command line after running commands in one answer and comments.
Also, I think the problem lies within the PATH setting but PATHs are already added.
image to enviornment variables, image to system variables

It is possible you failed to add python to your path in the installer.
Image displaying adding python to your path in the installer
You also may have forgotten to disable the path limit in the final set up screen.
Image displaying increase path limit in the installer
If you navigate to C:\Users\chira\AppData\Local\Programs\Python\Python38-32 then run python --version do you get any output?

Related

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.

Differing result from os.popen() between Pycharm and stock IDLE [Mac]

I've written a script to rename my photos according to the date they were recorded. It runs on mac and uses the CLI exiftool by phil harvey.
The command that create problem is the following:
os.popen("exiftool " + file path)
I wrote the script using Pycharm CE. I used the exiftool because it yielded the best results and was the easiest to use at the time. With the command mentioned above, I got all the metadata nicely formatted by the exiftool and it only needed to be separated and put in a list. I tried everything in the console of Pycharm CE before I wrote the script.
The script and the console of Pycharm both worked fine. However, I tried recently to run the script with the IDLE from python. The script failed because the return from the console was always an empty string. Upon further research I used the subprocess.run()method. The error was
CompletedProcess(args='exiftool PATH', returncode=127, stdout=b'', stderr=b'/bin/sh: exiftool: command not found\n')
The output was also empty.
My questions are now:
Why does the Console and the interpreter of Pycharm CE find the exiftool but the console and the IDLE of python don't?
Is there a way to include the installation location of the exiftool so it is found by the os.popen() / subprocess.run() methods in the IDLE and the console?
Many thanks for your help
AliSot2000
At your command prompt, type which exiftool to find the full path to the executable. Then, instead of just calling exiftool in your Python script, use the full path.
Turns out, using which exiftool was indeed the solution.
I deinstalled python, reinstalled the newer version and tried the fix, proposed in the comment. (Using said command in Terminal and calling the command with the full path) It worked in the IDLE once I installed Python 3.7. I ran previously Python 2.7 on my MacBook.
I still don't understand why 2.7 wouldn't work.
Anyway thanks for the tip.

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

pandas printing `tput: unknown terminal "emacs"`

I'm using pandas installed via Anaconda on Windows 10.
I run an IPython terminal inside an emacs inferior Python shell.
Every time I print a pandas.DataFrame to the terminal, I get an error message tput: unknown terminal "emacs".
The error message is then followed by the correct output so I wish I could just turn off the error message.
It seems similar to this question. For what it's worth, I do have Git/bin on my PATH environment variable but I don't know how this would affect anything.
Any advice would be much appreciated.
I ran into a similar problem while manipulating pandas.DataFrame in the debug perspective of Eclipse (Mars 2) under Windows 7.
When trying to examine the content of the DataFrame the console would output :
tput: unknown terminal "emacs"
while the value would display (pending), and the debug session would freeze forever.
I identified that the tput command was indeed a unix command shipped in by cygwing :
D:\smouton>where tput
d:\smouton\cygwin64\bin\tput.exe
The workaround I set up is to modify the PATH variable before launching Eclipse. This is conveniently done by launching the following batch file instead of Eclipse executable :
REM Remove reference to "unixy" stuff before calling eclipse
REM This avoids 'tput: unknown terminal "emacs"' error when manipulating pandas dataframe
SET PATH=%PATH:;C:\MinGW\bin;d:\smouton\cygwin64\bin;=;%
REM launch eclipse
START "" "C:\Program Files (x86)\Eclipse\eclipse.exe"
This file simply removes C:\MinGW\bin and d:\smouton\cygwin64\bin from PATH, then starts eclipse.
I suppose a similar workaround can solve the OP's issue with IPython as well.
The fix that "jurasource" suggested was to inspect the PATH to see if there are any elements of the path that would not be recognized by windows but would instead be recognized by a unix-like operating system. That is why /git/bin would be an issues, that path is recognizable by a unix-like operating system but not windows.
set environment variable TERM=xterm, then restart pycharm's python console can solve this problem.
to do this, first try this in cmd.exe:
tput -T xterm # see if xterm is accepted. if not, try another one.

Categories

Resources