Python Forum
getting an import statement to work in my program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting an import statement to work in my program
#1
I have installed PyCharm as my python IDE.

Previously, I (think) I installed a module pygame that has USB joystick interfaces.

In my program,I want to insert the import statement but am having errors.

I have inserted import pygame and get a module not found error.
so, I know the directory where pygame was installed.. C:/users/barry

so I am trying import C:/users/barry and this doesn't work.

What am I doing wrong??
I have tried c\users\barry\pygame.py and a few other attempts so how do I get pygame imported?

Thanks
Reply
#2
Did you read my last post where i try to explain how this work?
So to to add some info will install pygame and test that it work,all from cmd.
# Test python
C:\>python -V
Python 3.9.5

# Test pip
C:\>pip -V
pip 21.2.4 from c:\python39\lib\site-packages\pip (python 3.9)

# Install
C:\>pip install pygame --upgrade
Collecting pygame
  Downloading pygame-2.1.0-cp39-cp39-win_amd64.whl (4.8 MB)
     |████████████████████████████████| 4.8 MB 1.3 MB/s
Installing collected packages: pygame
Successfully installed pygame-2.1.0

# Test that it work
C:\>python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.1.0 (SDL 2.0.16, Python 3.9.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>
>>> pygame.__version__
'2.1.0'
>>> exit()

C:\>
So when all work from command line in Configure a Python interpreter choose same version as interpreter,
so the root path that pip -V show,eg for me c:\python39 for you it will shown and other path.
Then will Pygame work in PyCharm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to Make Steganography Program Work For All Payload Types Stegosaurus 0 1,131 Sep-26-2024, 12:43 PM
Last Post: Stegosaurus
  I can't for the life of me get this basic If statement code to work CandleType1a 8 2,226 May-21-2024, 03:58 PM
Last Post: CandleType1a
  Can't get a new program to work jpotter0 2 1,726 Nov-28-2022, 03:40 AM
Last Post: jpotter0
  Cryptic Error with import statement Led_Zeppelin 2 3,598 Jan-11-2022, 01:13 PM
Last Post: Led_Zeppelin
  Why doesn't this print statement work? stylingpat 10 8,692 Mar-23-2021, 07:54 PM
Last Post: buran
  import statement in a virtual environment leodavinci1990 1 3,073 Mar-04-2021, 12:57 AM
Last Post: snippsat
  Does "import xlrd" work in Thonny? cnutakor 3 4,092 Apr-30-2020, 12:41 AM
Last Post: Larz60+
  import scalalib package doesn't work manu_brighter 2 3,722 Apr-17-2020, 06:36 PM
Last Post: snippsat
  return statement will not work TheTechRobo 2 3,313 Mar-30-2020, 06:22 PM
Last Post: TheTechRobo
  [split] import PIL dont work vedansh 1 2,628 Mar-29-2020, 10:00 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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