pygame py2app Library not loaded: #loader_path/.dylibs/libSDL-1.2.0.dylib - pygame

I wouldn't call myself a programmer and am unfamiliar with Mac and Linux, so any links or pointers to additional background would help greatly. I've started with the most basic pygame I could google, (from https://realpython.com/pygame-a-primer/). The test.py and test.app runs on my VM but not on anyone else's real Macs.
test.py file
import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.display.flip()
setup.py file
from setuptools import setup
APP = ['test.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
command to create the test.app
$ python3 setup.py py2app
The test.app runs fine on the VM, but whenever the test.app runs on a real Mac (tested 2, one ran on Catalina ver???) this error message appears:
Traceback (most recent call last):
File "/Applications/test.app/Contents/Resources/__boot__.py", line 101, in <module>
_run()
File "/Applications/test.app/Contents/Resources/__boot__.py", line 84, in _run
exec(compile(source, path, "exec"), globals(), globals())
File "/Applications/test.app/Contents/Resources/test.py", line 1, in <module>
import pygame
File "pygame/__init__.pyc", line 120, in <module>
File "pygame/base.pyc", line 14, in <module>
File "pygame/base.pyc", line 10, in __load
File "imp.pyc", line 343, in load_dynamic
ImportError: dlopen(/Applications/test.app/Contents/Resources/lib/python3.7/lib-dynload/pygame/base.so, 2): Library not loaded: #loader_path/.dylibs/libSDL-1.2.0.dylib
Referenced from: /Applications/test.app/Contents/Resources/lib/python3.7/lib-dynload/pygame/base.so
Reason: image not found
2020-05-02 11:27:50.309 test[931:15836] test Error
----------------------------
Working environment: VirtualBox 6.1, macOS Sierra (Version 10.12) with the following:
$ pip list
Package Version
----------- ----------
altgraph 0.17
certifi 2020.4.5.1
macholib 1.14
modulegraph 0.18
pip 20.1
py2app 0.21
pygame 1.9.6
setuptools 39.0.1
wheel 0.34.2
$ brew list --versions
freetype 2.10.1
gdbm 1.18.1
jpeg 9d
libmikmod 3.3.11.1
libogg 1.3.4
libpng 1.6.37
libtiff 4.1.0
libvorbis 1.3.6
openssl#1.1 1.1.1g
pkg-config 0.29.2_3
python 3.7.7
readline 8.0.4
sdl 1.2.15_1
sdl2 2.0.12_1
sdl_image 1.2.12_7
sdl_mixer 1.2.12_3
sdl_ttf 2.0.11_1
sqlite 3.31.1
webp 1.1.0
xz 5.2.5
Any ideas or pointers would be greatly appreciated. The actual program is an OhHell card game which supports Windows clients (via pyinstaller), but I'm also trying to support a Mac client to play with my friends on a Mac. Similar to the test.py and test.app (ohhell.py and ohhell.app) runs on the VM Mac but same issue/error occurs with real macs. I've just included the simplest code snippet that I was able to google that reproduced the exact error message.
-john

Workaround Solution: Linking to a dynamic library on a Mac with full path and What path does #loader_path resolve to?. Using the '$ install_name_tool -change "#loader_path/.dylibs/libSDL-1.2.0.dylib" "/Applications/test.app/Contents/Frameworks/libSDL-1.2.0.dylib" base.so' resolved the Library not loaded: loader_path/.dylibs/libSDL-1.2.0.dylib errors. I assume this hard codes the path, but with my friends it's fine to tell them to make sure it resides in the /Applications folder.
However a secondary problem came up, 'pygame.error: File is not a Windows BMP file'. I used py2app, so the pygame delete and reinstall threads didn't seem like a feasible solution (pygame unnecesary w/py2app), so switching the images to uncompressed bitmap (256 colors) worked.
For those curious, I did try Pyinstaller for Mac but that presented a whole new set of problems.

Related

Assertion Error while using stanford-sentiment-treebank-roberta.2021-03-11.tar.gz in ALLENNLP

I have created a virtual ubuntu machine and installed ALLENNLP,
In that and tried example from ALLENNLP demo website
I have executed below code
from allennlp.predictors.predictor import Predictor
import allennlp_models.tagging
predictor = Predictor.from_path("myLocalPath/stanford-sentiment-treebank-roberta.2021-03-11.tar.gz")
predictor.predict("a very well-made, funny and entertaining picture.")
which gave me below error.
>>> predictor.predict("a very well-made, funny and entertaining picture.")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.local/lib/python3.8/site-packages/allennlp/predictors/text_classifier.py", line 24, in predict
return self.predict_json({"sentence": sentence})
File "/home/.local/lib/python3.8/site-packages/allennlp/predictors/predictor.py", line 54, in predict_json
instance = self._json_to_instance(inputs)
File "/home/.local/lib/python3.8/site-packages/allennlp/predictors/text_classifier.py", line 40, in _json_to_instance
return self._dataset_reader.text_to_instance(sentence)
File "/home/.local/lib/python3.8/site-packages/allennlp_models/classification/dataset_readers/stanford_sentiment_tree_bank.py", line 114, in text_to_instance
assert isinstance(
AssertionError
But when I executed below code
from allennlp.predictors.predictor import Predictor
import allennlp_models.tagging
predictor = Predictor.from_path("myLocalPath/sst-roberta-large-2020.06.08.tar.gz")
predictor.predict("a very well-made, funny and entertaining picture.")
It worked.
Only difference between above two code is version of roberta-large train data
I have installed latest version of ALLENNLP in my virtual machine
I don't have NVIDIA graphic card in my virtual machine could this be a reason?
But then how come other version is working?
Please help
Allen NLP version was the issue it was ALLENNLP 2.1.0, It worked with ALLENNLP version 2.4.0.
Use command "pip install allennlp"
and then "pip install allennlp-models"
instead of "pip install allennlp==[some version] allennlp-models==[some version]"
or make sure you have version greater than or equal to 2.4.0.

cant install pygame in pycharm

First of all, I'm new to programming. So,forgive me for my mistakes. I've installed pygame in python IDLE. But when I try to install it in pycharm, this happens:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
(venv) C:\Users\ARMAN\PycharmProjects\GAMES>pip install pygame
Collecting pygame
Using cached https://files.pythonhosted.org/packages/0f/9c/78626be04e193c0624842090fe5555b3
Complete output from command python setup.py egg_info:
WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using WINDOWS configuration...
Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x86"?[Y/n]Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\setup.py", line 194, in <module>
buildconfig.config.main(AUTO_CONFIG)
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\buildconfig\config.py", line 210, in main
deps = CFG.main(**kwds)
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\buildconfig\config_win.py", line 576, in main
and download_win_prebuilt.ask(**download_kwargs):
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\buildconfig\download_win_prebuilt.py", line 302, in ask
reply = raw_input(
EOFError: EOF when reading a line
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\
(venv) C:\Users\ARMAN\PycharmProjects\GAMES>py -m pip install -U pygame --user
Collecting pygame
Using cached https://files.pythonhosted.org/packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-1.9.6.tar.gz
Complete output from command python setup.py egg_info:
WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using WINDOWS configuration...
Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x86"? [Y/n]Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-nykuwxyw\pygame\setup.py", line 194, in <module>
buildconfig.config.main(AUTO_CONFIG)
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-nykuwxyw\pygame\buildconfig\config.py", line 210, in main
deps = CFG.main(**kwds)
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-nykuwxyw\pygame\buildconfig\config_win.py", line 576, in main
and download_win_prebuilt.ask(**download_kwargs):
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-nykuwxyw\pygame\buildconfig\downloa
reply = raw_input(
EOFError: EOF when reading a line
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ARMAN\AppData\Local\T
(venv) C:\Users\ARMAN\PycharmProjects\GAMES>
I get an error. I've updated everything. Found a similar problem here:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000435070-Command-python-setup-py-egg-info-failed-with-error-code-1-whatever-package-I-try-to-install-.
But I can't understand the solution. So, please kindly help me.
This isn't my answer, but an answer from here:
Pygame docs recommends that you use Python version 3.6.1 or greater,
so I would suggest you to use the most recent non-beta version. Also,
some pygame wheels are not available to this version yet.
After the python installation make sure its added to your PATH
variable and try to install Pygame using this command given that you
are on windows:
py -m pip install -U pygame --user
If you get a PermissionError then
run the command prompt as administrator.
I hope this helps.

Selenium python library via docker, Chrome error failed to start: exited abnormally

I am trying to run some python scripts with the selenium library from within a docker container based on miniconda/anaconda, but I keep getting this error: selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. I am also using a python wrapper for xvfb to avoid opening a real Chrome window.
To reproduce this (from a running docker container):
root#304ccd3bae83:/opt# python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> from selenium import webdriver
>>> from xvfbwrapper import Xvfb
>>>
>>> with Xvfb(width=1366, height=768) as xvfb:
... my_driver = webdriver.Chrome('/opt/chromedriver/2.33/chromedriver')
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/opt/conda/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/opt/conda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/opt/conda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/opt/conda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/opt/conda/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.4.0-116-generic x86_64)
According to this: https://sites.google.com/a/chromium.org/chromedriver/help/chrome-doesn-t-start it seems someone may need to use a stand-alone version of Chrome that works for all users, but I am not sure how the docker build works, I guess the docker image is built as root, and all the code inside it is executed as root, so there should not be any issue with different users controlling Chrome.
This python code works fine on a normal Ubuntu laptop with X windows. I need to carefully pick both the versions of Chrome and chromedriver, at the moment when checking from within the running docker container:
root#304ccd3bae83:/opt# /opt/chromedriver/2.33/chromedriver --version
ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4)
root#304ccd3bae83:/opt# google-chrome-stable --version
Google Chrome 62.0.3202.75
These options helped solving the issue.
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--disable-setuid-sandbox")
One of them is needed when seeing Chrome failed to start: crashed.
Also: make sure there are no zombies (from previous executions) for the chrome-driver process using ps aux | grep chrome-driver to find the PIDs to kill.
Bare in mind that if you are using the Python multiprocessing library to spawn many processes involving their own instance of the Chrome browser, then you can not use Docker (which is supposed to start just one Python process, unless using stuff like supervisor), so you may see: selenium.common.exceptions.WebDriverException: Message: chrome not reachable if you try anyway.

Kivy pygame error

I've been trying to get Kivy to work on my Mac (Lion), but I've been encountering issues. I followed the instructions on the Kivy site, and since Kivy 1.8 supports Python 3, I wanted to run it with 3.3, and I finally got that to work, by editing the kivy file to point to 3.3 instead of 2.7. I tried drop a .py program on the Kivy icon, the app opened but nothing happened. So I tried to run it from the command line. It opened 3.3, as expected, but I got the following error.
Python 3.3.4 (default, Mar 6 2014, 20:14:14)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Kivy.app/Contents/Resources/lib/sitepackages/pygame/__init__.py", line 127, in <module>
from pygame.base import *
ImportError: dlopen(/Applications/Kivy.app/Contents/Resources/lib/sitepackages/pygame/base.so, 2): Symbol not found: _PyCObject_Type
Referenced from: /Applications/Kivy.app/Contents/Resources/lib/sitepackages/pygame/base.so
Expected in: flat namespace
in /Applications/Kivy.app/Contents/Resources/lib/sitepackages/pygame/base.so
I have no idea why I would get this error, since I previously installed pygame for 3.3, and import pygame or from pygame.base import * work error free. Would this issue with pygame explain why .py files fail to execute when I drop them onto the Kivy icon?
Kivy.app and all the dependencies included in it is compiled with and for Python 2.7. You cannot use it for 3.3.
If you want to try Kivy with 3.3, you also need to compile Kivy yourself :)

Error when trying to install Django CMS in virtualenv w/ MySQL on Mac OSX

I am getting the following error when I try to install django CMS with MySQL using virutalenv:
RuntimeError: maximum recursion depth exceeded
/Users/ethan/Sites/env/build/mysql-python/distribute-0.6.28-py2.7.egg
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/Users/ethan/Sites/env/build/mysql-python/setup.py", line 7, in <module>
use_setuptools()
File "distribute_setup.py", line 145, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "distribute_setup.py", line 125, in _do_download
_build_egg(egg, tarball, to_dir)
File "distribute_setup.py", line 116, in _build_egg
raise IOError('Could not build the egg.')
IOError: Could not build the egg.
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /Users/ethan/Sites/env/build/mysql-python
The command I am using for the install is the following:
env/bin/pip install --download-cache=~/.pip-cache -r reqs.txt
And the reqs.txt file looks like this:
django-cms==2.4.1
Django==1.5.1
django-classy-tags==0.4
South==0.8.1
html5lib==1.0b1
django-mptt==0.5.2
django-sekizai==0.7
six==1.3.0
Pillow==2.0.0
django-filer==0.9.4
cmsplugin-filer==0.9.5
django-reversion==1.7
mysql-python==1.2.4
I'm a novice to django (just going through the tutorial) and I cannot find anything in a search that seems to resolve this issue. Anyone have any ideas?
Change your requirement to mysql-python==1.2.5, I had the same problem on a CentOS 6.3 server.
mysql-python v. 1.2.4 has a hard dependency on distribute version 0.6.28. It might not be picking the right version of distribute.
Run this after the virtual env is activated:
easy_install distribute==0.6.28
and you should be good to proceed with
env/bin/pip install --download-cache=~/.pip-cache -r reqs.txt
change requirement to mysql-python==1.2.5 also worked for me on OS X mavericks with pip install