Python unable to start [duplicate] - python-2.7

This question already has an answer here:
Can not execute python script or go to python shell
(1 answer)
Closed 7 years ago.
I am trying to run Python 2.7 from terminal, but it is not opening the python shell. Instead it gives an attribute error. The screen shot is attached below
What is the error? The python IDE's are working fine.

You have a local file that is shadowing the abc system library. When python starts, it is loading /home/hduser/abc.py instead of the system library abc. Remove or rename that file and you should be good!

Related

Python cannot find file in current directory with PowerShell

I'm trying to set up a new coding environment for myself so that I may learn Python at home on Windows 10. I already installed Python 2.7 and I am able to run it in PowerShell using the python command. However, when I try to get it to run other files (namely HelloWorld.py) it is getting an error
C:\Python27\python.exe: can't open file 'HelloWorld.py': [Errno 2] No such file or directory
I am in the same folder as HelloWorld.py on PowerShell and when I type ls, it appears on the screen. Most of the other questions I've seen on here were resolved by changing the environment variables in System to include python, but I have already done that. I am looking for anything else to try.

Running a python script in windows

I am new to Python.
I am executing a script in windows, but it does nothing and gives an error "invalid syntax".
Can you help me with the error. I have set the PATH variable to include my python.exe location.
Please see attached image:
Your image is from the python command line, only python commands are accepted there and there is no need to specify python in the beginning (in the shell python is just a call to the python interpeter).
In order to run windows commands in python use the os or subprocess modules.

Python script.py once saved now won't load as before

I have just started looking & learning Python (on Ubuntu 14.04) using the website: http://learnpythonthehardway.org/book/ and http://www.codecademy.com/
Yesterday, I worked for an hour on a few scripts namely 1-4 and named them as ex1.py etc and they executed fine. Today, I have come back to carry on with a few more exercises and tested my first exercises only to find now I get "SyntaxError: invalid syntax" when attempting "python ex1.py" with or without .py I have tried "#!/usr/bin/python" in any script header also. The path/Dir I have been using to test my Python scripts in is simply 'Python' within my Home Dir. I checked the actual file permissions but that appears to make no difference.
I am not too sure if it's an OS setup issue; Python issue; or simply me. Python seems great, so any ideas on what I'm doing wrong? What has changed since yesterday to my python.py script files?
The problem is that you are in the Python interpreter, and not the Linux terminal. This is indicated both by the error messages you saw and by the >>> prompt.
Exit the interpreter by holding down control and pressing the D key. You will then be back in the Linux terminal and running a script will work the way you expect it to.

Beginner Python spam.py

I am new to python, just got the learning python book and got stuck with the spam.py in the command line. The book says to make a file named spam.py and then ask python to run this by typing
%python spam.py
I have added the python to my PATH as it was C:\Python27 so I can call Python in the Windows CMD, but this just will not run. The error I receive is
>>>python spam.py
File "<stdin>", line 1
python spam.py
^
SyntaxError: invalid syntax
I appreciate any help that you can give.
Your problem is that you're trying to run your code from within the Python interpreter itself (the >>> prompt is the giveaway here since that's the Python prompt).
Exit from the interpreter (with CTRL-Z and ENTER for Windows) and run it from cmd.exe (the c:\> is the prompt in the example below):
c:\> python spam.py
From within the interpreter, you can also run an external file with:
execfile('spam.py')
Could you post the code from spam.py...
You seem to be trying to run the spam.py from the Python interpreter. Go to where the file is in Windows Explorer and launch it from there, using the C:\Python2.7\python.exe CLI.
By the way, since you didn't understand the syntax error warning, please see:
http://dictionary.reference.com/browse/SYNTAX
http://dictionary.reference.com/browse/SEMANTICS
You are trying to execute Python script file within the interpreter. Come out from the Python interpreter by pressing CTRL+Z and then ENTER key.
Then execute with the command :
Say, C:/> python spam.py
In order to run a python program you have to run program in Command Line not in Python Interpreter (press Windows Sign + R and type cmd.exe)
Moreover you have to remember to be exactly in the directory where your file is saved, e.g.:
If the file file is C:\Python27\spam.py you have to be in C:\Python27.
To change the directory:
use dir to display the folders and files in current place
use cd to change your directory (e.g. C:\Python27\>cd Spam moves you to C:\Python27\Spam
use Tab key to autocomplete names of the commands, folders and files
As you said you have added Python to PATH and followed my instructions, the statement below should work perfectly
python spam.py
Hope I could help.
If for example, your file is in G: drive, type this in cmd:
python G:/myfile.py
Basically, type in the path. Just doing "cd" won't work in Python

easy_install not working-windows 8 64 bit [duplicate]

This question already has answers here:
python3 --version shows "NameError: name 'python3' is not defined"
(2 answers)
Closed 6 years ago.
I'm sure I'm missing something obvious, so I apologize in advance. Here's the situation:
I'm trying to install some python modules to work with excel documents, however, I can't even get the easy_install command to work. Both python and python\scripts are in my system path, and I've run the setup tools script several times. I've checked the scripts folder, and it contains both the easy_install script and the .exe file. However, when I try to run it from the command line, I receive a traceback error:
>>> easy_install
Traceback (most recent call last):
File "", line 1, in
easy_install
NameError: name 'easy_install' is not defined`
this is a 64-bit Windows 8 machine.
What am I missing here?
easy_install is a shell command .
To use easy_install on windows follow these steps:
press window + r and type cmd then press Enter
probably easy_install.exe is not in your system path, so type the full path to easy_install:
C:\Python27\Scripts\easy_install.exe name_of_the_package then press Enter.
I suggest you to read this: http://pythonhosted.org/distribute/easy_install.html#windows-notes