0
After numerous problems with Tkinter and Pyinstaller, I finally managed to make a Unix executable application work normally on MAC High Sierra. But inside my application folder, there is a folder called script, which I use chdir(os.getcdw()+'/scritp')
to open it.
The problem is precisely in using the executable for Mac OS done with pyinstaller. When I click on such executable, it understands that os.getcdw()
is precisely the user folder. It does not take the folder where the executable file is.
For example, instead of os.getcdw()
be equal to "/Users/isaacvictor/Desktop/scriexe"
he returns "/Users/isaacvictor"
How do I resolve this issue? I want to grab the executable file folder.
Many thanks to all who contribute.
The
os.getcwd()
returns the current working directory, if you want to use another you can open, something like:meu_dir = os.open( "/Users/isaacvictor/Desktop/", os.O_RDONLY )
, and then set it as your standard working dir :os.fchdir(meu_dir)
, when you call theos.getcwd()
will work.– Tuxpilgrim
@Interesting tuxpilgrim, what’s the difference of opening a fd pro directory, than simply use
os.chdir("/Users/isaacvictor/Desktop/")
directly? I think it’s the same thing, it’s much more complex.– nosklo
So @nosklo suggested this option because it was the first one I thought about. As for your question, taking a look at doc (in a Linux scenario)we have that the two are virtually identical except for the fact that the
os.fchdir()
gets a fd. This implies that not only directories can be passed by parameter, since in Linux everything is treated as a file, so sockets and devices can be opened and your fd recovered, thus giving to carry out operations on them. So for this case theos.chdir()
is the best solution ;)– Tuxpilgrim
Complementing: from the version 3.3 python’s
os.chdir()
also supports the file Descriptor as input.– Tuxpilgrim