How do I get the full path of the current file's directory?
Yes, I already tried these methods. They all give me the folder that contains Blender.exe
which is D:\program\Blender 2.90
And what I supposed to get is C:\Users\username\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\someAddonFolder right?
Is something changed in version 2.9?
Without the Blender environment, I mean run under normal Python. Methods from that topic all work well.
Did I miss something?
The old way I made the script work is by putting .blend .json .py all together in the same folder.
and refer to the relative path using //
bpy.utils.user_resource('SCRIPTS', "addons")
use this code can get you the path your custom addon you install at.
for me, it's 'C:\Users\Naoki\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons'
found the answer over here:
https://blender.stackexchange.com/questions/20850/how-to-automatically-get-a-add-on-folders-path-regardless-of-os
Related
I've been trying to access a folder outside my current folder, however when I Use "../images/image.png" it gives a FileNotFound error. Now running this code in IDLE gives no error and works perfectly. How can i use ../ in Vs code?
Using pygame.display.set_icon(pygame.image.load(f"./images/ui/logo.png")) which gives :- FileNotFoundError: No such file or directory. running it in IDLE 3.9, doesnt give me any error
The first thing to understand is that if the code in vscode involves paths, everything is retrieved for the root directory based on the workspace. Even if you use "." in a deep directory under the workspace, this still represents the workspace directory, instead of the current directory.
So what we need to do is to change our thinking and import the files you want with the workspace as the root directory.
This also means that ".." will not appear in vscode. Because all the files we need are in the workspace, we will not use the parent directory outside the workspace.
For example,
"./images/ui/logo.png"
If you place it like this, you can retrieve the file anywhere in the workspace without complex positioning based on the current file.
You can refer to this issue. It has similar problems with you.
I am assuming that both folders are in the same directory. This means that you should use “./“ instead of “../“ :)
I am beginning to look at python, so when I found a tutorial it said that the first thing to do would be to download python from www.python.org/downloads/
Now when I downloaded python 3, I then started the installation and got to
Why would I want to "Add Python 3.5 to PATH"? What is PATH? Why is it not ticked by default?
PATH is an environment variable in Windows. It basically tells the commandline what folders to look in when attempting to find a file. If you didn't add Python to PATH then you would call it from the commandline like this:
C:/Python27/Python some_python_script.py
Whereas if you add it to PATH, you can do this:
python some_python_script.py
Which is shorter and neater. It works because the command line will look through all the PATH folders for python and find it in the folder that the Python installer has added there.
The reason it's unticked by default is partly because if you're installing multiple versions of Python, you probably want to be able to control which one your commandline will open by default, which is harder to do if both versions are being added to your PATH.
In addition to what #SuperBiasedMan stated, you can edit your PATH in Windows by hitting Start > Run, then type sysdm.cpl.
From there, navigate to Advanced tab and then hit Environment Variables.
In the lower section, where it says 'System variables', find the one named PATH and double click it. Note that it would be easier to copy and paste it to a notepad or something. The separator as you can see is a semi-colon.
Any path that you add to this variable, will be looked when you type any command in a cmd window or through the 'Run' command line.
That's the same concept as in Linux, I just pointed out how it can be edited.
This shows the way if you haven't add python to PATH(By the way, the python.exe is in my Python directory)
This is the way if you add python to a PATH
I am developing a web app that relies on NodeJS and the Express module in which I am trying to run a Python script from an express route. What I would like to do is store the Python script in /public/scripts/test.py and refer to it using a relative URL such as /scripts/test.py so that Node doesn't need to know anything about the environment in which it is running.
I've attempted to execute the Python script both by using the python-shell module and by simply using Node's built-in ChildProcess. In both cases I'm running into the same issue – the path to the Python script seems to treated as being absolute and thus the script isn't executed, resulting in a file not found error.
How can I go about invoking a Python script with a relative URL? I'm rather new to web development, so I would not be surprised if I was simply misunderstanding the situation.
EDIT:
As jfreind00 pointed out, process.cwd() can be used to identify the present working directory on top of which a URL to the script can be built. Worked like a charm.
Turning my comments into an answer so you can mark this question as resolved.
Invoking a program from node follows all the normally expected path rules. If you precede the path with a /, then the system looks in the root of the current directory volume. If you don't want node to know about your external directory structure, then set an environment variable for the location or path prefix for your python script and have the node script read that environment variable. Either way, node has to either know about the actual path, it has to be in the node current working directory or it has to be in the path and you have to run it with something that will search the path.
If you want to see what the current working directory is in your particular configuration, then you can use:
console.log(process.cwd());
to see what the current working directory is so you can see how to base your path on that.
I realise this question may already exist, but the answers I've found haven't worked and I have a slightly different setup.
I have a python file /home/pi/python_games/frontend.py that I am trying to start when lxde loads by placing #python /home/pi/python_games/frontend.py in /etc/xdg/lxsession/LXDE/autostart.
It doesn't run and there are no error messages.
When trying to run python /home/pi/python_games/frontend.py, python complains about not being able to find the files that are loaded using relative links eg: /home/pi/python_games/image.png is called with image.png. Obviously one solution would be to give these resources absolute paths, but the python program also calls other python programs in its directory that also have relative paths, and I don't want to go changing all them.
Anyone got any ideas?
Thanks
Tom
you could change your current working directory inside the script before you start calling your relative imports, use os.chdir("absolute path on where your script lives").
Rather than change your current working directory, in yourfrontend.pyscript you could use the value of the predefined__file__module attribute, which will be the absolute pathname of the script file, to determine absolute paths to the other files in the same directory.
Functions in theos.pathmodule, such assplit()andjoin(), will make doing this fairly easy.
I need to have the exact directory of an image for a game I'm making in python with pygame. I know what the folder and file are called, but not where my user puts it. Please help, I won't be able to continue my project without you guys :(
The file i'm trying to find is in the same folder as the .py and is a .bmp
If you know the path relative to where your python module is stored in the file system (as you seemed to indicate) you can use the following to calculate the abs path and then build up an appropriate path from there.
import os
print(os.path.abspath(__file__))
print(os.path.split(os.path.abspath(__file__)))
NOTE: Change print for python2.7
Use os.path.join to build up the new path.
Maybe have a look at the os.path documentation page, especially at os.path.abspath.