Traceback (most recent call last): File "main.py", line 1, in <module> from cmu_graphics import *

Question:

Replit Profile: https://replit.com/@Jbaier001

Hey, @Jbaier001 welcome to the forums!

Can you please provide a link to the repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

3 Likes

Based on your title, it looks like you’re trying to import cmu_graphics, but you might not have installed it. Try using pip install cmu-graphics in the Shell tab of your Repl.

I tried typing that in but I got the same error. So basically I used to be able to use cmu graphics in replit no problem. But now when ever I make a new file it gives me the error

Traceback (most recent call last):
File "main.py", line 1, in <module>
  from cmu_graphics import *
File "/home/runner/TinyImmediateSolution/venv/lib/python3.8/site-packages/cmu_graphics/__init__.py", line 5, in <module>
  main_sibling_filenames = set(os.listdir(main_directory))
FileNotFoundError: [Errno 2] No such file or directory: ''

But it does not do this with my old files and programs that run perfectly fine and access it no problem. I also typed in the pip install cmu-graphics but this did not work as the same error just came up. Nothing was changed or altered in my settings so I am unsure why I no longer have access to it.

Hey @Jbaier001 ! Can you try entering poetry add cmu-graphics?

In the section where the shell is or in the white command prompt where the coding goes? Sorry I am new to all this and can not contact any of my teachers about this.

In the shell, not the console.

when I type in the pip install cmu-graphics I had this pop up in the shell saying it was all satisfactory

~/birthday-test-project$ pip install cmu-graphics
Looking in indexes: https://package-proxy.replit.com/pypi/simple/
Requirement already satisfied: cmu-graphics in ./venv/lib/python3.8/site-packages (1.1.25)
Requirement already satisfied: pycairo>=1.20 in ./venv/lib/python3.8/site-packages (from cmu-graphics) (1.24.0)
Requirement already satisfied: certifi>=2020.6.20 in ./venv/lib/python3.8/site-packages (from cmu-graphics) (2023.7.22)
Requirement already satisfied: pygame>=2 in ./venv/lib/python3.8/site-packages (from cmu-graphics) (2.5.0)
Requirement already satisfied: Pillow>=7.2 in ./venv/lib/python3.8/site-packages (from cmu-graphics) (10.0.0)

Looks like cmu-graphics is buggy before python 3.9.
Fix:
Show hidden files and open the file venv/lib/python3.8/site-packages/cmu_graphics/__init__.py.
Replace line 4 with:
main_directory = os.path.dirname(os.path.abspath(__main__.__file__))

I tried it on my side and got an error about failing to build pycairo. Idk what that’s about, but I can’t help you any further. Sorry 'bout that.

Question: Anytime I make a new replit it gives me an error code related to the traceback of importing cmu graphics for python saying that it can not find the file. When I open up a old file it works just fine and has no problem importing it and displays the image. it only occurs when a new one is created, how do I correct this issue?

Repl link/Link to where the bug appears:
https://replit.com/@Jbaier001/birthday-test-project

**Screenshots, links, or other helpful context:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from cmu_graphics import *
  File "/home/runner/birthday-test-project/venv/lib/python3.8/site-packages/cmu_graphics/__init__.py", line 5, in <module>
    main_sibling_filenames = set(os.listdir(main_directory))
FileNotFoundError: [Errno 2] No such file or directory: ''

I also did the pip install cmu-graphics in the shell and it told me all the information was satisfactory.***

code snippet

How do I open the hidden files to make the change?

@Jbaier001 click the 3 dots next to Files and click Show Hidden Files.

1 Like

Try running the main.py directly with python main.py in the shell. That should sidestep the FileNotFoundError: [Errno 2] No such file or directory: '' error.

If this works for you, add run = "python main.py" to .replitand also delete the entired [interpreter] section.

Or you can fork the updated https://replit.com/@replit/Python-CMUGraphics?v=1 template with this error fixed.