My script don’t found a file under linux…
The file is a simple txt: pippo.txt
I’ve put it into the blender binary directory
and in the same dir of .blend that I use…
In the script
I’ve try to load with:
dir=“pippo.txt”
dir=".\pippo.txt"
dir="./pippo.txt"
dir="\pippo.txt"
dir="//pippo.txt"
dir=".//pippo.txt"
dir=".\pippo.txt"
Mhh…no, but I dont’want
a special path…I want only put the script and his relative
file (class, morphing, etc…) all in one directory: when the user
unzip the directory and open the .blend file, the script must
found all file …my wish is the user don’t modify the script by hand before use it…
But, in your opinion, where is the error in my test?
I’ve try all the combination…
You could still try to use the absolute path, but the user doesn’t need to do anything. You can get the Blender executable path like this:
import Blender, sys, os
filename = "pippo.txt"
# file in blender directory
blenderpath = os.path.split(sys.executable)[0]
filepath = os.path.join(blenderpath, filename)
filepath then contains the path to your file.
Note that sys.executable returns the full path to the running python interpreter, so you only get the blender directory when you run this from Blender.
If the file is in the directory the blendfile was loaded from you can replace the last part by this:
Oh ho…it’s true excuse me for the stupid question…
the python path is a old problem for Blender.
I’ve python istalled…
To solve definitively the problem without esoteric procedure,
I’ve copied this file in the Blender dir:
UserDict.py
stat.py
ntpath.py
os.py
In your opinion this is a wrong solution?
Can I distribute my script directly with this files?
You really should try to avoid that, you have PYHTONPATH set correctly? If so, have you tried any of the other often suggested methods, like setting the python directory in Blender (user defaults)?
Anyway, if you only need the os module for the filename stuff, you can use JMS’s suggestion instead for both Blendfile path and main Blender directory (the sys module is always available), or you could even code something yourself.