I'm learning to program Python from the "Learning Python the Hard Way". On one of the chapters it tells me to use pydoc command. The windows 7 cmd failed miserably with that command.
When I typed in pydoc raw_input() on cmd following error codes were generated:
'pydoc' is not recognized as internal or external command,
operable program or batch file.
I've looked back previous two questions on same issue:
Pydoc is not working (Windows XP)
How to get pydoc command working in Windows?
So far I have created a pydoc.bat with following line
#python c:\Python26\lib\pydoc.py %*
and saved it in C:\python27\Tools\Scripts.
I've also tried to change the PATH to C:\python27\Lib. I called the two variables python and pydoc because I'm not really sure I set the PATH correctly.
It's still not working.
What did I do wrong?
To get help on python when in the PowerShell window, type:
python -m pydoc raw_input
substituting your function name for raw_input.
Hey I know this post is a bit old, but I wanted to let you (and anyone else out there) know about this:
C:\Python27\Tools\scripts\pydocgui.py
It sets up a webserver on localhost:7464. Simply visit the address in your browser and you have access to pydoc :) Hope this helps someone
You added this to your script file:
#python c:\Python26\lib\pydoc.py %*
But it seems that you are using python 2.7
I run a Windows 7.
I am using the command prompt, cmd.
I am learning Python from Learning Python the Hard Way.
I was having the same problem as you, and attempted to solve it on my own from what you gave me.
Here is what I got:
On gedit, I typed
#python C:\Python27\Lib\pydoc.py %*
It is important to note two parts:
The C:\ is capitalized, the L in Lib is capitalized.
Both of those were left under-cased, and that created a syntax error when I tried to run it.
I saved this as
pydoc.bat
from gedit in C:\Python27\Tools\Scripts.
From cmd, I cd'd into the above address. From C:\Python27\Tools\Scripts I typed pydoc.bat open
and it worked. It showed me the information I needed.
The only difference between what you did and what I did seems to be the capitalization of certain letters.
Check your typing and ensure it fits what the computer needs to see.
Copy paste the bat file in this path.
C:\python27
and then run it as :
pydoc.bat raw_input
this should work. make sure that the PATH is set to:
C:\python27
This will help you to run the bat file from anywhere in the cmd line
set the path as
C:\Python27>python (or wherever you installed python)
Then write command -m pydoc raw_input
which will look as
C:\Python27>python -m pydoc raw_input
Note: There's a space between python and -m
There are several ways to fix it:
Check if path you've added to PATH is in there.
Type in command line PATH. If path you've added isn't there then Restart Windows.
If it is go next line.
Type pydoc.py instead of pydoc
If you don't want type pydoc module extension every time, just add .PY extension
to PATHEXT variable located at the same place as PATH variable does
(Computer → Properties → Advanced system settings → Advanced → Environment Variables...
→ System Variables → PATHEXT). Restart your Windows after adding of extension.
Type Pydoc.py x replacing x with whatever document you want to read.
For example Pydoc.py raw_input (in cmd ofcourse)
Do not forget to change path to the lib directory. do it like this:
Right click on my computer>properties>Advanced tab>environment variables> search for the value PATH in system variables>edit> enter this -> ;C:/Python27/lib
Here's how you do it from zero/layman (my kind of) condition, learning python:
If you have a Win7 32bit system with no environment variable set manually after installing (basically nothing else done after just installing it) python 2.7 or any version lower than python 3 from website, then follow these steps:
1) Open Command Line, and type (in exact case):
cd\
until you come back to "C:\" directory (root/base directory where your python is installed).
2) Then type:
cd Python27
As my base dir or drive is C drive, my path is this, yours may be different
hence you type the route of Python27 (or 26 or the name of your python folder) folder where you have installed Python2.7 (or whatever version).
3) Then type:
cd Lib
You just entered the Library folder where pydoc.py file is present as per default installation from internet (for me it was the case).
4) Then simply type:
pydoc.py
You will get the required pydoc output which seems to be of the kinds of "man" page of PERL/Linux or the "Help" of C/Windows.
5) Then simply type:
pydoc.py raw_input
Name of the required command for which you want to see documentation.
Now you know how to do it for all the rest of the commands.
you must not be in correct directory in your command prompt while typing "pydoc raw_input"
first type:
cd\python27\lib
then type:
pydoc raw_input
I have the answer: see the thing is we been running pydoc raw_input in the cmd, but what we where forgetting is that to run python files we have to type .py at the end of the file
im using windows 7 NVidia, to run you got to be in it's Dir C:\Python27\Lib, then type pydoc.py and enter.
There you go hope this was helpful.
Related
I am running Windows 10. I have recently changed location to my python folder and interpreter.
Unfortunately, when i now run python scripts in command prompt, I always have to type "python" before the name of the script I want to run.
Running the script directly - for example: C:\Python 37\mypythonscript.py -generates absolutely no reaction from the command prompt. I simply get back directly to C:\Python37>
If I however run C:\Python 37\python mypythonscript.py, the script is properly executed.
I have changed all the file associations using "ftype" and "assoc" in the command prompt. When I start command prompt and type "python", the python compiler correctly starts.
My problem is that I always have to type "python" before the name of my script for the command prompt to recognize that it needs to execute python.
I would like to open command, change directory to the directory with my python scripts, and simply run the python scripts by running the name of the scripts (mypythonscript.py) without having to type "python" in front of it.
Could you please help me identify what is wrong? How can I once again run python scripts in the command prompt without having to type "python" in front of the script's name?
Thank you in advance.
If you use a python 3 Virtualenv in powershell the above problem can be very confusing. Typically "py .\yourscript.py" or "py .\yourscript" will work but ".\yourscript.py" or ".\yourscript" will fail and might return a "ModuleNotFoundError: No module named '<module>' " error.
This happens because your .py association is not correct as described by Eryk Sun in the above second remark. The "py launcher" he names is, in most cases, "C:\Windows\py.exe". I my case it was already installed and I just needed to adjust the .py extension as described by him. It can also be done via the "Choose default apps by file type" settings.
A useful help is to define "$env:PYLAUNCH_DEBUG=1" in your powershell. After that "py .\yourscript.py" will have extra output showing where your python executable is found.
If there is no extra output it means, as before, that you don't have ".py" associated with "py.exe". If you start a "cmd" and "ftype python.file" looks ok, you need to read Eryk Sun's first remark :-)
I am trying to access Python through a Windows command prompt, but am at an office and cannot add an Environment Variable. So, I cant follow the advice provided here. Thus, I added a User Environment Variable through User Accounts and use Variable:python and Value: C:\Python33. When I do a Windows Run check on %python% I reach the required Python33 folder. However, when I type python -Version in the command prompt I get the error 'python' is not recognized as an internal or external command, operable program or batch file. I am not sure how to proceed.
Run Python from the command prompt and include the full path to python.exe. For example to get the version:
C:\Python33\python.exe --version
When you run a script you specify the path to the script if you're not in the directory where the script is located. For example, if your script is in C:\scripts and is called my_script.py:
C:\Python33\python.exe C:\scripts\my_script.py
Instead of setting environment variables, you can use the whole path, like Neo wrote e.g.:
C:\Python33\python.exe yourPythonScript.py
Remove any environment variables you have added.
C:\Python33\python.exe pyscript.py should work.
I once Had a similar problem, but i couldnt find any solution, not even adding the path to the python folder was working.
Then I opened Python and clicked in File, then browser path, and I found that I had another folder that contained the real Python folder, not the default one. Maybe it could work for you too.
I've been writing code in python 3.3.5, but whenever I run one of my py files, it is always ran in python 2. I used to have python 2.7 installed, but then I uninstalled it, so I don't know why this is the case. Even when I type in "python" on command line, it comes up with "python 2.7.3 default", even though I deleted it. I can prove this because one of my scripts is this:
print("Hello)
input()
print("Bye")
input()
It says hello, then gives a traceback error when I hit the enter key. But if I change the coding so that the inputs are instead raw_input, then it works fine. Also Tkinter works instead of tkinter. Yet I am coding this all with python 3.3.5
Since you mentioned having problems assigning your PATH variables to the correct execution location in Windows, you might try the following:
Edit your environment variables
Scroll down to Path, select path, click edit.
Add C:\Python27; You should in your case have 2 versions of python there. If you don't you could add the following:
C:\Python27;C:\Python335;
Navigate to the Python27 folder in C:\ and change python.exe to python2.exe
Navigate to the Python335 folder in C:\ and change python.exe to python3.exe
Open up command prompt and type python2
Then, in command prompt, type python3
You should see different output at this point denoting that you have different versions active.
My command prompt is currently running Python 3.2 by default how do I set it up to run Python 2.7 by default, I have changed the PATH variable to point towards Python 2.7, but that did not work.
UPDATE:
It still does not work. :(
Still running python3 - to be specific it runs python3 when I am trying to install flask - which is what I want to do.
More generally, when I simply type python into the command line, it does nothing.
I get a 'python' is not recognized as an internal or external command, operable program, or batch file error.
No idea what to do.
If you call your Python scripts directly using python script.py then setting the PATH to have the 2.7 directory first should be enough.
If you want to call Python scripts indirectly with the shell, i.e. by writing just script.py or by executing the file from the explorer, you need to set the 2.7 installation as the default program handler for the .py extension. The easiest way to do that is to run the Python installer again and choose the option “make this installation the default”.
Note that with the new launcher, that ships with 3.3+, you don’t need this, as you can specify the version number using a shebang line and the launcher will automatically pick the appropriate interpreter.
Changing your PATH environment variable should do the trick. Some troubleshooting tips:
Make sure you didn't just change the local, but rather the system variable to reflect the new location
Make sure you restarted your CL window (aka close "cmd" or command prompt and reopen it). This will refresh the system variables you just updated.
Make sure you remove all references to C:\Python32\ or whatever the old path was (again, check local and system PATH - they are both found on the same environmental variables window).
Check to see if Python3.2 is installed where you think it is... (just rename the directory to something like OLD_Python3.2 and go to your CLI and enter "python" - does it start up? If it does is it 2.7? or 3.2? If not, you did something wrong with your PATH variable.
All else fails - reboot and try again (you might have some persistent environment variable - which I don't see how that can be - but hey, we are brainstorming here! - and a reboot would give you a fresh start.
If that doesn't work then I'd think you are doing something else wrong (aka user error). CMD has to know where to look for python before it can execute. It knows this from your PATH variable... now granted, I work almost exclusively in 2.6/2.7, so if they did something to the registry (which I doubt) then I wouldn't know about that.
Good luck!
Change the two las lines to you current python desired build path:
Windows Registry Editor Version 5.00
' Extracted from Python 2.7 silent installation By Elektro H#cker
[HKEY_CLASSES_ROOT\.py]
#="Python.File"
[HKEY_CLASSES_ROOT\.pyc]
#="Python.CompiledFile"
[HKEY_CLASSES_ROOT\.pyo]
#="Python.CompiledFile"
[HKEY_CLASSES_ROOT\.pyw]
#="Python.NoConFile"
[HKEY_CLASSES_ROOT\Python.File\Shell\Open\Command]
#="CMD /K \"\"C:\\Program Files (x86)\\Python\\Python.exe\" \"%1\" %*\""
[HKEY_CLASSES_ROOT\Python.NoConFile\Shell\open\command]
#="CMD /K \"\"C:\\Program Files (x86)\\Python\\Pythonw.exe\" \"%1\" %*\""
Could you try this as root:
$ ln -s python2.7 /usr/local/bin/python
Logout & login again as root:
$ python -V
It works for me, hoping the same to you.
Cheers,
I've downloaded python installer from http://www.python.org/ftp/python/3.1.2/ , this python-3.1.2.msi file, I need to execute some python files? How do I do that? For example in php I'd do php filename.php from console, I do however have python command line but I don't know how to execute those files.
So if I could set ENV variable to directly execute my file(s) if that is possible that would be great.
There is an option in the installer called "Register Extensions" to associate Python files with the interpreter, so double-clicking them or entering filename.py in the console should work.
Apart from that you might want to add C:\Python31 to your PATH variable (right-click on My Computer, choose Settings, choose the Advanced Tab - there you can access the system variables. Better do this as an admin.
If you type python in the Windows command line, what happens? Is the Python interpreter in your PATH yet?
If not, add the Python installation directory there (here's a good guide). Then just do python script.py just like with PHP.
you can just execute
python yourfile.py
Or if the python command don't work you have to give the absolute path to you python installation or add it to windows path