Shakespeare Programming Language Help - Windows - python

I've recently gotten interested in the esoteric programming language Shakespeare Programming Language (SPL) and have tried to install the only windows-friendly interpreter I could find, from:
https://pypi.python.org/pypi/shakespearelang/0.2.0
It was my first time installing pip and python (3.6) as a whole, although I believe I have installed everything correctly.
When I try to interpret a legitimate SPL file with:
shakespeare run helloworld.py
I get the error:
File "c:\...\shakespearelang\shakespeare_interpreter.py", line 151, in run_event
self._character_by_name(name).on_stage = True
AttributeError: 'NoneType' object has no attribute 'on_stage'
Everything else in the interpreter seems to work properly except calling the someone to "the stage".
Any fix to this error or an alternative windows-friendly compiler/interpreter would be great.

You asked:
Any fix to this error or an alternative windows-friendly
compiler/interpreter would be great.
Here is an alternative you could try. It is a web-based "IDE" for building and running SPL programs.

I believe that the file should be helloworld.spl instead.

Related

Python Environment Setup seems complicated and unsolvable

So, I've been a dev for about 3 years, primarily working in TypeScript and NodeJS. I'm trying to broaden my skillset by learning python (and eventually expanding my learning of Computer Vision, Machine learning, etc.) but I feel incredibly frustrated by trying to get Python to work consistently on my machine. Surely I'm doing something wrong, but I just can't really understand what it is.
I've run into these problems mostly when using ML packages (TensorFlow, Whisper, OpenCV (although I was eventually able to resolve this), so I don't know if it's related to M1 support of one of the common dependencies, etc.
My current understanding of python is that:
M1 support of python is version dependent at best.
venv is the only environment manager I should need to use
I should use pyenv to install python versions so as to not conflict with os-installed python (macos dependencies)
I'll use the latest project I'm working on as an example.
My Machine and Environment
Mac M1 Pro, MacOS Monterey 12.6
pyenv 2.3.9
Python 3.7.13
Fish Shell version 3.5.1
My general workflow to get a project started:
Create virtual environment using venv
python3 -m venv <some_environment_name>
Open created directory using VSCode, and activate the virtual environment
Here is where I encounter my first issue, which seems to be persistent.
➤ source /Users/paal/src/whisper_transcription/bin/activate.fish
functions: Function '_old_fish_prompt' does not exist
~/src/whisper_transcription/bin/activate.fish (line 18):
functions -c _old_fish_prompt fish_prompt
^
in function 'deactivate' with arguments 'nondestructive'
called on line 30 of file ~/src/whisper_transcription/bin/activate.fish
from sourcing file ~/src/whisper_transcription/bin/activate.fish
(Type 'help functions' for related documentation)
functions: Function 'fish_prompt' does not exist
~/src/whisper_transcription/bin/activate.fish (line 47):
functions -c fish_prompt _old_fish_prompt
^
from sourcing file ~/src/whisper_transcription/bin/activate.fish
(Type 'help functions' for related documentation)
fish: Unknown command: _old_fish_prompt
~/src/whisper_transcription/bin/activate.fish (line 71):
_old_fish_prompt
^
in function 'fish_prompt'
in command substitution
(whisper_transcription)
So, what I do to resolve this is add the following if statement to the fish.config file.
if type -q $program
_old_fish_prompt
end
Looking at GitHub issues, this seems to be a persistent issue for fish shell and this seems to at least temporarily resolve it.
Or, I just switch to ZSH.
OK, so with that resolved I move on. The environment is activated, I'm using ZSH now, and I can successfully run a python script that prints "hello world" to the console.
Then comes the nightmare of installing any packages. It seems like any project I start has some weird edge case of compatibility issues. Between M1 processors, Python Versions, builds not working correctly, etc.
for example..
import whisper
... # rest of file
This with any other code or even by itself throws the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import whisper
File "/Users/paal/src/whisper_transcription/lib/python3.7/site-packages/whisper/__init__.py", line 12, in <module>
from .decoding import DecodingOptions, DecodingResult, decode, detect_language
File "/Users/paal/src/whisper_transcription/lib/python3.7/site-packages/whisper/decoding.py", line 514
if prefix := self.options.prefix:
^
SyntaxError: invalid syntax
This appears to be some problem with the Python Version. From what I understand, the := operator isn't valid syntax until Python 3.8. However, dependencies of whisper (PyTorch) only seems to be supported up to version 3.7.9
So, you can see, it seems like I just end up in these bizarre circular problems where some dependency of some package I want to use isn't supported by either the platform or the current python version, and they seem basically unsolvable (at least with my current knowledge of python)
Why is this seemingly so complicated? I'm clearly doing something wrong here, and obviously I'm out of my comfort and knowledge zone, but these issues feel very daunting and opaque, and difficult to actually troubleshoot this in any consistent or clear way.
Is there a resource that makes this stuff more clear? Is Python development on M1 chips just this broken at the moment? How can I get past these seemingly basic issues to start actually learning?
I'm not necessarily looking for a solution to this specific problem here, but if theres general advice about environment management and how to make things work somewhat reliably, I'm fine troubleshooting. I just feel like every time I start trying to learn, I end up in these rabbit holes that take hours and hours to fix and sometimes don't even really resolve things.

Invalid Literal Stockfish python 3.10

I am trying to use the stockfish package in python on Linux, and I'm running into a rather odd error. I downloaded the zip file from the official repo:
https://github.com/official-stockfish/Stockfish
And I've unzipped it and used the makefile to compile it. However, when I try to initialize stockfish in any bit of actual code:
stockfish = Stockfish(path = "/username/Chess/Engines/Stockfish-master/src/stockfish")
I get the following error:
File "/username/.conda/envs/alpha/lib/python3.10/site-packages/stockfish/models.py", line 57, in __init__
self._stockfish_major_version: int = int(
ValueError: invalid literal for int with base 10: 'dev202211114nogit'
I've tried a couple of the unofficial binaries for linux as well (found here: https://stockfishchess.org/download/linux/), and they've also given me the same error, albeit with a slightly different string in the final line.
I'm really unsure as to what's going on, since I've tested my installation method on a different (much weaker, hence my desire to fix this issue) computer, and it worked fine with all the same setup. I'm using python 3.10, with stockfish 3.28.0. If anyone has experience with this particular issue, or if they have any advice as to how to begin solving it, I would sincerely appreciate it. If there are any details that I've omitted that might be of use, please let me know and I'll edit them in. Cheers.

AttributeError: dlsym(RTLD_DEFAULT, run): symbol not found - meaning

I am attempting to use the PyMultinest package. The full error text I am encountering is AttributeError:dlsym(RTLD_DEFAULT, run): symbol not found in the __getitem__() function in ctypes/__init__.py. I'll include more text and code below, but I am mostly trying to understand what this error is telling me - my Google Fu is apparently lacking, and the StackExchange questions I have seen relating to this error seem to be hyper-focused on solving a specific instance of this error. So - What is this error trying to tell me is wrong?
More context. I attempt to execute the PyMultinest (PMN) package as directed in the PMN documentation. PMN is, effectively, a Python wrapper for a C program. Running PMN requires a fair bit of setup code (several ancillary functions need to be defined, as well as a host of variables), which I'm not including here by default because it's ... a lot, but I can if needed. The PMN execution line I use is
pmn.run(Loglike, Prior, ndims, n_live_points=1000, n_params=n_params, outputfiles_basename='./'+ProjectName+'/temp_', resume=False, verbose=True)
This returns the error traceback
File "[redacted]", line 139, in <module>
pmn.run(Loglike, Prior, ndims, n_live_points=1000, n_params=n_params, outputfiles_basename='./'+ProjectName+'/temp_', resume=False, verbose=True)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymultinest/run.py", line 254, in run
lib.run(*args_converted)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__
func = self.__getitem__(name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, run): symbol not found
If it helps, I have determined that the name variable being passeed through self.__getitem__(), and thus into self._FuncPtr(), is run. Although, that might be obvious looking at the AttributeError message.
I am running Python 3.8 (as shown above) on a MacOS machine. Last summer, I was able to execute PMN on this machine using extremely similar code to that which I am using now. I am currently trying to optimize my code from last summer, which is why I'm surprised it isn't simply "working".
So far my attempts at fixing this have been mostly centered on reinstalling PMN. I have done a clean install (pip uninstall/pip install) of the PMN package, as well as following the PMN documentation to rebuild the C portion of the package. I have included the source directories of the C software in my Path variables - or at least, I tried to, I am assuming I was successful, but I'm not very familiar with Macs.
Ultimately, I just wish I understood what Python was telling me with this error better. It would help me direct my own attempts at solving the issue. I suspect it is saying "We don't know where to find this 'run' command you're asking for," in which case I need to figure out why my Path variable changes aren't working. Am I on the right path?
Some hints how to resolve this are given in these issues:
https://github.com/JohannesBuchner/PyMultiNest/issues/160
https://github.com/JohannesBuchner/PyMultiNest/issues/163
It is important to cleanly recompile (empty build folder) when the environment changes, so that cmake recognises changed libraries and compilers.
Check if you are running everything with python3 and not python (works as python 2.x is you have both version 2 and 3 installed)
Check is all the PyMultiNest python files are rewritten in python 3 style, e.g. $ print "something" becomes $ print("something")
My supervisor was accidentally running on python 2.7 and got the same error, so your error might as well be due to mismatch of python version usages.
Run command flutter pub cache clean and flutter clean and after that run flutter pub get now relaunch your emulator it worked for me.

PySerial Attribute Error with 'read_until'

I need some help troubleshooting an Attribute Error in my Python code.
I am working with a serial device connected by a /dev/ttyUSB0 to a Raspberry Pi 2B. My goal for this code is to read live serial data continuously from the serial device and separate out commands delineated by an '#' symbol instead of /n or /r.
This project is still in its early stages but from some quick research I've done the pyserial attribute 'read_until' would work perfectly as its backbone. This would allow me to read in one byte at a time and stop at an '#' symbol, and afterwards process the data before moving on to the next portion of serial data.
For some reason I get an Attribute Error when I try to use 'read_until' claiming that the 'Serial' object does not have this function. Below is the test code I am using and the error it spit back out:
import serial
gc = serial.Serial('/dev/ttyUSB0', baudrate = 230400)
print(gc.name)
def getCommand():
gcData = gc.read_until('#', 1).decode('ascii')
print(gcData)
getCommand()
gc.close()
And here is the output that this code gave me:
>>>
/dev/ttyUSB0
Traceback (most recent call last):
File "/home/pi/Python/GC/serialRead1.py", line 10, in <module>
getCommand()
File "/home/pi/Python/GC/serialRead1.py", line 7, in getCommand
gcData = gc.read_until('#', 1).decode('ascii')
AttributeError: 'Serial' object has no attribute 'read_until'
>>>
The frustration behind this is that 'read_until' should have been imported along with the serial library. Perhaps I am missing something quite simple, but it would be very helpful if I could use this attribute. Most other questions about 'read_until' are referencing the 'telnetlib' which as far as I know is not the same as what PySerial has.
Here is a link to the website where I found the documentation saying that 'read_until' should belong to PySerial: https://pyserial.readthedocs.io/en/latest/pyserial_api.html
Just so you are aware, I am very new to programming in general. Some of the jargon that seasoned programmers like yourselves use might go over my head and so I may have no idea how to perform the solutions you have. I ask for your patience as I learn more about programming and Python in general.
Thank you very much for your time!
It seems you have PySerial version 2.6 installed. This version was released in 2011, while the read_until method was added in 2015.
The easiest way to install the latest version (as you've discovered) is to use pip:
sudo apt install python3-pip
python3 -m pip install --user pyserial
Note that using pip with sudo is bad practice.
It's best to use a virtual environment or to use the --user flag, as demonstrated above.

Getting PyBox2D working on all platforms (Windows, Linux and Mac)

I'm trying to get my Box2D code running fine on all 3 plaforms. It's working fine on Windows for me, I simply installed Python 2.5, set my env path, and then downloaded PyBox2D from the following location:
http://code.google.com/p/pybox2d/downloads/list
And installed. At that point, it just seems to work, at least based on my tests. One caveat however is that when I run the testbed app pygame_main.py it fails... But perhaps it was just not updated from a pybox2d change or something like that...
On Linux, how to do this is tricky, and more so on how to actually distribute a game... We've installed Python 2.5, and checked out the trunk of pybox2d from svn, built it and ran the setup. However when we actually try to make a world
File "box2dtest.py", line 28, in main world = box2d.b2World(worldAABB, gravity, doSleep)
TypeError: init() takes at most 3 arguments (4 given)
This is an error I got when I tried to build the game to Python 2.7 as well. I am not sure what to do from here to be honest.
I could toy with the idea of giving up on getting it to work on Linux if I could be sure it worked fine on Mac. I would love it to run perfectly on all systems :) Honestly, in my idealized world, the setup for the game would be simple. I'm just looking for people to help me figure out if I am running into a dead end, or if there is hope for getting this working. :)
Let me know what other information I can provide to help describe the problem. My partner set it up on linux so that is why my description is not too verbose on the linux side.
It would have helped to have some more context for the code. On code line 28, you call b2World with to many parameters. The examples/hello.py in the distribution calls b2World() like this:
b2World(gravity=(0,-10), doSleep=True)
so from the variables names you pass a parameter, I guess you have to leave out worldAABB.

Categories