Issue with Python module downloads from Library for a beginner Python coder.

Cameron Simpson cs at cskk.id.au
Sun Aug 2 05:38:30 EDT 2020


Diverting replies to tutor at python.org, a better place for all this.

It looks like the error is in graphics.py, not in your file.
Your line:

    from graphics import *

is syntacticly correct. Something has mangled the line breaks in your 
traceback, which here appears as:

    When I write a different line -  (from import graphics *), this is the output:
    from graphics import *Traceback (most recent call last):  File 
    "<pyshell#3>", line 1, in <module>    from graphics import *  File 
    "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", 
    line 1    Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) 
    [MSC v.1926 32 bit (Intel)] on win32           ^SyntaxError: invalid 
    syntax

To me it appears that the syntax error in in graphics.py at line 1. I'd 
normally expect such a traceback to look more like this:

    File "<pyshell#3>", line 1, in <module>
        from graphics import *
    File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1
         Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
         ^SyntaxError: invalid syntax

In particular, the "^" would point to the place in the code where Python 
_noticed_ the syntax error. Is it possible that graphics.py contains 
that "Python 3.8.5 ...." text?

So the traceback I've invented above says that _your_ import failed, but 
that was because of a failure in the file you were trying to import.

BTW, it looks to me like your Python programmes (graphics.py and 
whatever other file you might be making) are inside the Python install.  
Normally you'd keep these elsewhere, for example in a folder such as:

    C:\Users\sarvesh\my-programmes

Cheers,
Cameron Simpson <cs at cskk.id.au>

On 02Aug2020 06:36, Sarvesh Poddar <sarvesh.poddar at yahoo.com> wrote:
>I am currently using Python 3.8.5 with IDLE environment that comes 
>pre-installed with the Python application. I am using the book "An 
>Introduction to computer science" by John Zelle as my reference.
>The problem I am facing is "There is a python program named "graphics.py" that is used as reference in the book and I downloaded the python file from internet (link to the file - https://mcsp.wartburg.edu/zelle/python/graphics.py). I have kept this module in (C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32) and this is were my Python files also lie in C drive. The problem is that I am not able to import graphics.py file and when I try to do that following is the error I receive,
>Traceback (most recent call last):
>  File "<pyshell#0>", line 1, in <module>    import graphics
>  File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1
>    Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32           ^SyntaxError: invalid syntax
> I have installed, uninstalled and then re-installed Python 3.8.5 multiple times but the problem remains. I did a thorough internet search and most of them suggested using sys path and following is the result,
>
>import sys>>> sys.path['', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\idlelib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
>When I write a different line -  (from import graphics *), this is the output:
>from graphics import *Traceback (most recent call last):  File 
>"<pyshell#3>", line 1, in <module>    from graphics import *  File 
>"C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", 
>line 1    Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) 
>[MSC v.1926 32 bit (Intel)] on win32           ^SyntaxError: invalid 
>syntax


More information about the Python-list mailing list