Python Forum
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Graphics py not found
#1
Windows 10
Python 3.6

copied graphics.py file from link on website but i get an error message:

Traceback (most recent call last):

  File "C:\Users\<user name>\Desktop\w.py", line 2, in <module>
    from graphics import *
ModuleNotFoundError: No module named 'graphics'


...........when running code with import to it.
Any ideas?

the file is correctly named graphics.py and copied to the ...python\python36\lib\site packages

any ideas greatly appreciated?
Reply
#2
Quote:...python\python36\lib\site packages
This resembles the path.

lib is capped, site packages is really site-packages
the path would something like
C:\Python36-32\Lib\site-packages
If C:\Python36-32 is where you installed python then that is the path you need to put it.

And this has nothing to do with GUI coding so i moved your post.
Recommended Tutorials:
Reply
#3
Do this.
>>> import sys
>>> sys.path
The list you get is where Python look for .py files.
Reply
#4
You can't just put graphics.py in C:\Python36-32\Lib\site-packages. You have to write __init__.py if you want Python to see a directory with some .py files as a package. Even if __init__.py is a completely empty file.

Or you can add the direcotory of the graphycs.py to PYTHONPATH environment variable.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
(Apr-03-2017, 06:00 PM)wavic Wrote: You can't just put graphics.py in C:\Python36-32\Lib\site-packages. You have to write __init__.py if you want Python to see a directory with some .py files as a package. Even if __init__.py is a completely empty file.

Or you can add the direcotory of the graphycs.py to PYTHONPATH environment variable.

Thanks I'm sure you are right but being a novice i dont follow the 'write_init_.py' part ..i have no idea what this means.

I followed instructions for adding graphics.py from various web sites which stated that the file needs to be placed in the ..\site-packages folder. The supplied readme in that folder also states that 3rd party files/modules need to be placed there..so i'm sure it is in the correct location.
The instructions state that this is where Python will be able to 'see it'.

I ran the sys.path which output 5 different paths including the one above which is where the file is.

if there is a separate procedure for adding the directory i.e to PYTHONPATH env variable i don't know of this

..Ok ..Ive checked the environment variable path which is defined under user variables. I've also added the same path to 'System Variables'  but still i get the same error message . graphics not found
Reply
#6
I have not gotten to that part yet. Writing a module. Don't know what __init__.py should contain. You can try just to create an empty one and put it on the same site-packages/module_name/ directory.

See this

The PYTHONPATH is part of the system environmental variables. Any program can create their own. This is a list of directories where Python looks for modules or packages. A single .py file could be a module and you can import it like any other: import module_name. If the file has a name module_name.py. But this file have to be in the same working directory or its location have to be in PYTHONPATH. Or you can the location of graphics.py to the PYTHONPAT:

import sys

sys.path.append("/home/user/my_modules/")
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
The problem is not with making a module/package wavic.
Quote:I ran the sys.path which output 5 different paths including the one above which is where the file is.
Then it should work,there most be something else that's going on.
Do you only have 1 Python version?
Here some test you can run:
# Test which python
>>> import sys
>>> sys.executable
'c:\\python36\\python.exe'
>>> exit()

# Test pip
C:\>pip -V
pip 9.0.1 from c:\python36\lib\site-packages (python 3.6)
C:\>
So making a module as a test(which is just a single python file like graphics.py)
#foo_1.py
import os

print('Running {}'.format(os.path.realpath(__file__)))
I place foo_1.py in my 36 site-packages folder.
Test that it work:
C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo_1
Running C:\python36\lib\site-packages\foo_1.py
>>> exit()
C:\>
Reply
#8
I have only the one python version

None of the above works and throws syntax errors

...even 'c:\>python' throws a 'unexpected character after line continuation character' error

no idea ..myabe i just wasn't supposed to use Python:-(
Reply
#9
(Apr-05-2017, 12:05 PM)vnc Wrote: ...even 'c:\>python' throws a 'unexpected character after line continuation character' error
You are mixing up the use Python interactive shell and cmd
Introduction to the Windows Command Prompt(cmd)

To make your error and fix it:
I start cmd:
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. Med enerett.

C:\WINDOWS\system32>cd\
C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> c:\>python
  File "<stdin>", line 1
    c:\>python
             ^
SyntaxError: unexpected character after line continuation character
>>> exit()

# Now i am on command line and not python shell
C:\>python -V
Python 3.6.0

C:\>pip -V
pip 9.0.1 from c:\python36\lib\site-packages (python 3.6)

# Start shell again
C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello world')
hello world
>>>
Reply
#10
I get it thanks ..never realised cmd could be used for python.

So the above is fine but i still have no idea on how to use use graphics.py. It still can't be accessed ..via the cmd shell either?

i.e from graphics import*
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python graphics kaltenherz 1 1,722 Sep-05-2021, 05:19 PM
Last Post: jefsummers
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,548 Nov-23-2020, 05:15 PM
Last Post: cananb
  from graphics import * jmaloney413 2 5,225 Oct-18-2018, 08:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020