dbm.error: db type is dbm.bsd, but the module is not available (Python 3.0) - python-3.x

I'm trying to open a shelve file that I created in 2.5, but I get the error I listed in the question title.
The data aren't essential, but I really want them.
Looking at the lib\dbm\__init__.py file it recognizes 4 types of dbm modules but only finds dbm.dumb on my system.
Does anyone know how I can open this?
Is there a bsd.py file like the dumb.py file?
Would I have to install 2.5 to get at it?
Also, I may have had Panda installed on my old installation when I created this file.
Is the Python installation that comes with Panda standard or might this file have come with it?
Thanks!

bsddb is part of Python 2.5 (AND 2.4 AND 2.6...) but not of 3.0 -- it was removed (long story...:-). Get it for 3.0 from pypi, recover your data into some other form (sqlite is my personal recommendation), and live happily ever after!-)

Related

How can i preserve the source raster projection when using gdal_translate?

I'm currently working on a small raster refining tool. The goal is, to have a simple CLI tool, to compute tiles from a georeferenced source raster and create a corresponding index.shp. For this I'm using python 3.7 and gdal. The tool runs smoothly and generates the expected tiles and shapefile, but it gets rid of the projection, which is stored in the source raster. Qgis defaults the newly computed tiles to EPSG 4326 while informing me about an unknown projection. The original raster is in EPSG 25832.
My Setup:
Windows 10 64 bit
Python 3.7.2
Gdal I cannot access the specific version, since gdal-config is not installed and I cannot make it work, but it is 64-bit and I installed it through the binaries provided on gisinternals.com. Windows software list says GDAL 204 MSVC 2017.
While running the script, I get error messages telling me about missing files, e.g. pcs.csv, datum.csv ellipsoid.csv and so on. This indicates that having those files, would fix my problem.
But oddly enough, I have used Osgeo4W to install, python 2.7 with gdal and it works like a charm, of course having adjusted the python parts. Tiles get calculated and stay in the projection of the source. Without any external files which specify a projection, in fact using the exact same data which is really confusing to me.
To my understanding, there is no flag or option which forces gdal to keep the projection. If have overlooked or missunderstood the docs im glad for advice.
Before anyone asks, i know that using the osgeo4w installer is obviously the easy and working solution here. But keeping in mind that python 2.7 will soon be discontinued and also using this as a chance to learn new things i wanted to build a 3.7 based tool with gdal installed on my machine
The corresponding code looks like this and does the following :
1.) Command string is build
2.) string is handed to os.system, which in turn executes accordingly
for i in range(0, width, tilelenght):
y = 0
for j in range(0, height, tilelenght):
gdaltranString = f'gdal_translate -of GTIFF -srcwin {i}, {j}, {tilelenght}, {tilelenght} {input_filepath} {output_filepath}{x}_{y}.tif'
subprocess.run(gdaltranString)
y = y+1
x = x+1
The expected result, would be a collection of functional .tif files which have the EPSG code of the source file, in this case 25832.
But as already mentioned, the projection gets lost somewhere in the process.
So,i have found the solution to my problem, without really understanding how it became an issue to begin with.
The solution was to create an user variable GDAL_DATA with the path to the projection definition files.
The weird thing is, i now have GDAL_DATA, as system variable and user variable, both pointing to the same directory.
If someone knows more about the mysterious ways of windows system variables, please share your wisdom, or the source of said wisdom.

After adding libraries to dymola, i can't connect it to Python via buildingspy

After i have made some libraries load directly when i open Dymola by modifying the file : "c:/program files (x86)/dymola 2016 fd01/insert/dymola.mos" , and adding those lines :
Utilities.setenv("MODELICAPATH","C:/Users/hrameh/Desktop/EnergySystems_V2-73p/ModelicaLibraries/ExternalMedia-master/Modelica/ExternalMedia 3.2.1");
openModel("C:\Users\hrameh\Desktop\EnergySystems_V2-73p\ModelicaLibraries\ExternalMedia-master\Modelica\ExternalMedia 3.2.1\package.mo");
Utilities.setenv("MODELICAPATH","C:\Users\hrameh\Desktop\EnergySystems_V2-73p\ModelicaLibraries\EnergySystems");
openModel("C:\Users\hrameh\Desktop\EnergySystems_V2-73p\ModelicaLibraries\EnergySystems\package.mo");
Utilities.setenv("MODELICAPATH","\illuin\users$\hrameh\Mes documents\Dymola");
The model works completely fine in Dymola. But, when trying to simulate the model via Python using the buildingspy library, the simulation fails. Any suggestions to help me find a solution?
I guess your problem is, that buildingspy relies on the default working directory path Dymola gets when the dymola.exe is called by buildingspy - but the openModel-commands in your dymola.mos change the working directory.
Use
openModel("<path-to-package.mo>", changeDirectory=false);
to avoid this.
Additionally, with newer Dymola versions, you must ensure that no saved startup directory is used, by selecting: Edit -> Options -> Settings -> Do not save Startup directory.
As you currently use Dymola 2016 FD01 this is not a problem for you at the moment.
Such problems can be detected by showing the Dymola window when buildingspy simulates a model. You can do this with showGUI as shown in this minimum example:
import os
from buildingspy.simulate.Simulator import Simulator
os.environ["PATH"] += os.pathsep + "C:/Program Files (x86)/Dymola 2016 FD01/bin"
s = Simulator("Modelica.Blocks.Examples.PID_Controller", "dymola")
s.showGUI(show=True)
s.simulate()
Some further hints for your example:
You do not need the Utilities.setenv()-calls to open a library. openModel is sufficient
I would not use Utilities.setenv, as this is an undocumented and apparently a very old package (creation date is from 2004). Use Modelica.Utilities.System.setEnvironmentVariable instead. This way you also don't get an extra package loaded in the package browser
Using the file /insert/dymola.mos has some disadvantages:
it is used system wide by every user, so it should not contain paths to user directories
if you install a new dymola version, you must edit the insert/dymola.mos file of this installation again
Alternatives to dymola.mos
In Dymola 2016 FD01 use the file setup.mos instead to add the openModel commands (located in C:\Users\\AppData\Roaming\Dynasim)
Newer Dymola versions don't have setup.mos anymore, but setup.dymx for the settings and startup.mos for the user commands (to open libraries, etc.)

Octave: xlsread function undefined + causes octave crash

I'm new to this, so I'll try to explain clearly.
I'm using Octave (4.x) to process data and I want to import an Excel file. Excel is installed on my laptop as well.
[num,txt,raw] = xlsread(input.rootdir);
When the function is called, the following message appears:
warning: Functions for spreadsheet style I/O (.xls .xlsx .sxc .ods .dbf .wk1
etc.) are provided in the io package. See <http://octave.sf.net/io/>.
Please read <http://www.octave.org/missing.html> to learn how you can
contribute missing functionality.
warning: called from
__unimplemented__ at line 524 column 5
CreateInvoices at line 18 column 3
error: 'xlsread' undefined near line 18 column 5
error: called from
CreateInvoices at line 18 column 3
>>
The warning appears that the I/O package is not installed. However, the package is listed when I call 'pkg list' in command line, so it seems to be installed correctly.
pkg list
There are some other topics on stack overflow with a similar content, but they seem to be solved with proper installation of the I/O package.
If I try to call 'pkg load io', Octave crashes immediately.
I tried to use other functions to import data (csv, textread, ...), but I always lose my text data. So that is not really helpful.
Does anyone have some advice for me?
Thanks in advance for the reply!
Best regards,
Lode
I've just done this, but in Linux (Xterm windows with bash). I had to install liboctave-dev package first, then the io octave package. Then the call to 'pkg load io' before using it. But need to make sure to install with root privileges or the package won't be found by a shared Octave installation. Of course, this was not on windows but might provide some clues.

Can you read the length of an mp3 file in python 3 on windows 10?

I am currently creating a music player in python 3.3 and I have a way of opening the mp3/wav files, namely through using through 'os.startfile()', but, this way of running the files means that if I run more than one, the second cancels the first, and the third cancels the second, and so on and so forth, so I only end up running the last file. So, basically, I would like a way of reading the mp3 file length so that I can use 'time.sleep(SongLength)' between the start of each file.
Thanks in advance.
EDIT:
I forgot to mention, but I would prefer to do this using only pre-installed libraries, as i am hoping to publish this online as a part of a (much) larger program
i've managed to do this Using an external module, as after ages of trying to do it without any, i gave up and used tinytag, as it is easy to install and use.
Nothing you can do without external libraries, as far as I know. Try using pymad.
Use it like this:
import mad
SongFile = mad.MadFile("something.mp3")
SongLength = SongFile.total_time()

Any tips on creating a Pygame Developer Console?

I've been getting my feet wet with Python and Pygame, and after a few bugs in a very basic game that I have been making, I've thought to myself that having some sort of console that can deal with string input (from a developer) would be very handy.
Here's an example:
I notice the player disappears after double jumping. So, in the console that I will hopefully create, I would type in:
>> report_bug("Player disappears after double jumping")
Where report_bug(string) is a user-defined function that will do the following things:
report_bug(string):
# Check if debug file already exists; create new file if none exists
# Append string to file, along with other extra info
Could someone point me in the right direction? Will I have to create something from scratch, and if so, how would I go about doing that? I've attempted to modify the source code from: http://www.pygame.org/project-pygame-console-287-.html, however it is 9 years-old and made for Python 2.x, when I'm using Python 3.4. Any help would be greatly appreciated.
I've managed to get the 2.X PygameConsole version 0.7 working, so I will stick with that!
Edit: I will attempt to port PyConsole to Python 3.X and hopefully add some more features so newcomers can easily understand what is going on.

Resources