I can't import pygame
inside pycharm
.
I've been using Linux Mint 19, Anaconda 3, Pycharm 2019.3.1.
I've created a conda environment and install pygame: conda install pygame -c cogsci
Then I ran (my_env) tiago@tiago-XPS-8700:~$ python3 mycode.py
. And I got the following error:
teste.py:3: RuntimeWarning: use mixer: libSDL_mixer-1.2.so.0: cannot open shared object file: No such file or directory (ImportError: libSDL_mixer-1.2.so.0: cannot open shared object file: No such file or directory) pygame.mixer.music.load('bat.mp3') Traceback (most recent call last): File "teste.py", line 3, in pygame.mixer.music.load('bat.mp3') File "/home/tiago/anaconda3/envs/pycharm/lib/python3.5/site-packages/pygame/ init .py", line 105, in getattr raise NotImplementedError(MissingPygameModule) NotImplementedError: mixer module not available (ImportError: libSDL_mixer-1.2.so.0: cannot open shared object file: No such file or directory)
After reading some blog at internet I installed sudo apt install libsdl-mixer1.2
.
After that if I run (my_env) tiago@tiago-XPS-8700:~$ python3 mycode.py
at Linux terminal at my conda environment, my code run successfully.
But If I try to run the same code inside Pycharm
I get the following error:
/home/tiago/anaconda3/envs/pycharm/bin/python /home/tiago/Documentos/PYTHON/cursoemvideo/exercicios/ex_021.py Traceback (most recent call last): File "/home/tiago/Documentos/PYTHON/cursoemvideo/exercicios/ex_021.py", line 3, in import pygame File "/home/tiago/anaconda3/envs/pycharm/lib/python3.5/site-packages/pygame/ init .py", line 133, in from pygame.base import * ImportError: libSDL-1.2.so.0: cannot open shared object file: No such file or directory
Process finished with exit code 1
What am I missing?
在 conda 环境中,他们预先安装了软件包和库,您可以通过导入它们轻松使用它们,但在 pycharm 中,您还需要安装该软件包,以便您可以在 pycharm 中使用它
Inspired by this questions Tensorflow and Pycharm , I ran Pychram from the Linux Terminal at my conda environment and it worked! If I run Pycharm from Linux Mint Menu I still can't import pygame
. Addicionally, I inserted the following statement at my .bashrc
so that I can run pycharm from anywhere in the Linux Terminal.
# Open bashrc to edit
nano .bashrc
# Add the comand line below to the end of file
# You should adapt to your path to "pycharm.sh', mine is "/opt/pycharm-community-anaconda-2019.1.3/bin". In another computer I found it at "/var/lib/flatpak/app/com.jetbrains.PyCharm-Community/current/active/files/pycharm/bin"
export PATH=$PATH:/opt/pycharm-community-anaconda-2019.1.3/bin
# Then close the terminal and reopen it in order to the modifications in .bashrc take effect
# At terminal you run
pycharm.sh
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.