简体   繁体   中英

I can`t import wxpython in anywhere except python console

I installed python 3.8.8 and installed wxpython using pip at terminal

pip install wxpython

and i run simple program

import wx
print(wx.version())

in pycharm and pycharm`s python console, I got

ModuleNotFoundError: No module named 'wx'

in IDLE, I got

Traceback (most recent call last):
  File "C:/Users/tasoo/OneDrive/Desktop/wx.py", line 1, in <module>
    import wx
  File "C:/Users/tasoo/OneDrive/Desktop\wx.py", line 2, in <module>
    print(wx.version())
AttributeError: partially initialized module 'wx' has no attribute 'version' (most likely due to a circular import)

in python.exe code works

I want to import wx in pycharm project. I tried add python in system path but it didn`t work.

You have problem because you saved code in file wx.py and now import wx loads your file wx.py instead of module wx . Rename your file - ie. main.py instead of wx.py


PyCharm may have own Python installed and it may need to install wx in this Python.

Check

import sys 
print(sys.executable) 

to get full path to Python used by PyCharm and then use this path

/full/path/to/python -m pip install wx

Or search in PyCharm settings (in menu File ) and change Python Interpreter .

In PyCharm for every project you may set different Python - if you have installed many versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM