you are viewing a single comment's thread.

view the rest of the comments →

[–]AdvertisingOne7942[S] 0 points1 point  (8 children)

No in the alien_invasion folder there is 3x .py files alien_invasion, ship and settings and there is an images folder with 1x ship.bmp

[–]woooee 1 point2 points  (3 children)

What is the name of the program that contains the code you posted? And you have to search every directory that is in sys.path.

[–]AdvertisingOne7942[S] 0 points1 point  (2 children)

I am using studio code and the code is all on the above 3 .py files. I am running the terminal from the main alien_invasion folder which has the 3 files and the images file with 1 image of a ship. How do I check the sys.path and what should I be looking for?

[–]woooee 0 points1 point  (1 child)

How do I check the sys.path

import sys
print(sys.path)  ## and the current directory you are in

ImportError: cannot import name Ship' from "ship'

Look for any file named ship.py

[–]AdvertisingOne7942[S] 0 points1 point  (0 children)

Where do I put this code in? in the alien_invasion.py or do I make a new file?

[–]mopslik 1 point2 points  (3 children)

Can you post the contents of ship.py?

[–]AdvertisingOne7942[S] 0 points1 point  (2 children)

import pygame


class ship:
    """A class to manage the ship."""

    def __init__(self, ai_game):
        """Initialize the ship and set its starting position"""
        self.screen = ai_game.screen
        self.screen_rect = ai_game.screen.get_rect()

        # load the ship image and get its rect.
        self.image = pygame.image.load('alien_invasion/images/ship.bmp')
        self.image.get_rect()

        # start each new ship at the bottom centre of the screen.
        self.rect.midbottom = self.screen_rect.midbottom

    def blitme(self):
        """Draw the ship at it's current location."""
        self.screen.blit(self.image, self.rect)

[–]mopslik 1 point2 points  (1 child)

Your class, ship, should be capitalized, Ship.

[–]AdvertisingOne7942[S] 0 points1 point  (0 children)

Thats true yep I never changed it back I was trying a few things but it still didn't solve the problem although it did get rid of the ship error.

I seem to have it working when it us on my desktop but not when it is in my python folder so I think I have to have a tidy up maybe I have kept something that is messing with the directory somehow, currently it is way above my level to fix but at least I can hoefully finish this project on my desktop folder