Posts: 59
Threads: 9
Joined: Apr 2019
Ok, guys. Major stupidity on my part. I have mad an exe file and post it on sourceforge.net, but the program will not work.
This, because the main file and secondary ones required extensions (images, audio, etc), which are indicate by window path (C:/Users/Desktop/"My name"/Project/image.png)
I totally forgot the part, when it goes to another computer it will never work, because the computer path will not be the same one as mine. Anyway to fix this, to a default path or something, so all the files call be called and work?
Any replies much appreciated. Again major error and stupidity of my part, i totally forgot about that.
Posts: 480
Threads: 86
Joined: Feb 2018
import os
from pathlib import Path
d = Path(__file__).parent
sound = os.path.join(d, 'Folder', 'Keep adding folders/files till you get to the file')
Posts: 4,489
Threads: 69
Joined: Jan 2018
Apr-22-2019, 07:09 PM
(This post was last modified: Apr-22-2019, 07:09 PM by Gribouillis.)
I think you want package data. See also the module importlib.resources for accessing package data from the code (starting with 3.7, before that it was pkg_resources )
Posts: 59
Threads: 9
Joined: Apr 2019
But, for example, if i change it only C:\Project will not work?
Posts: 480
Threads: 86
Joined: Feb 2018
Apr-22-2019, 07:37 PM
(This post was last modified: Apr-22-2019, 07:38 PM by SheeppOSU.)
Linux users do not have "C:"
And I'm also pretty sure someone on Linux has regular slashes - /
Posts: 59
Threads: 9
Joined: Apr 2019
(Apr-22-2019, 07:37 PM)SheeppOSU Wrote: Linux users do not have "C:"
And I'm also pretty sure someone on Linux has regular slashes - /
Ok, right now, just for windows, then for others. i would love to get this to work. and see what portuguese people think about it and improve it based on the feedback i hope to receive
Posts: 480
Threads: 86
Joined: Feb 2018
(Apr-22-2019, 07:12 PM)francisco_neves2020 Wrote: But, for example, if i change it only C:\Project will not work? I guess that is fine. If I'm correct, you mean to put all the pictures and stuff there, if so, that will work.
Posts: 59
Threads: 9
Joined: Apr 2019
(Apr-22-2019, 07:05 PM)SheeppOSU Wrote: import os
from pathlib import Path
d = Path(__file__).parent
sound = os.path.join(d, 'Folder', 'Keep adding folders/files till you get to the file')
Man i didn't get the part until i get the file. There is one major pyw file, within this major pyw file there is from subprocess call others pyw. This major file has attached to it one png, then there are 2 or 3 secondary with png attached also and one with 10 png images(slideshow). The one with that code will be the major one, where i will indicate all the other files, except itself)?
Posts: 480
Threads: 86
Joined: Feb 2018
Apr-22-2019, 08:04 PM
(This post was last modified: Apr-22-2019, 08:06 PM by SheeppOSU.)
I don't exactly get the question, but if you're asking but with a lot of pictures you could just do this -
import os
from pathlib import Path
d = Path(__file__).parent
x = 0
picList = ['file.png', 'file.png', 'file.png', 'file.png']
for i in picList:
picList[x] = os.path.join(d, 'Pic Folder', i)
x += 1 Hope i didn't make any mistakes on there
Oh! I just remembered - If they are in the same directory as the file you just have to put the name of the picture
Posts: 59
Threads: 9
Joined: Apr 2019
(Apr-22-2019, 08:04 PM)SheeppOSU Wrote: I don't exactly get the question, but if you're asking but with a lot of pictures you could just do this -
import os
from pathlib import Path
d = Path(__file__).parent
x = 0
picList = ['file.png', 'file.png', 'file.png', 'file.png']
for i in picList:
picList[x] = os.path.join(d, 'Pic Folder', i)
x += 1 Hope i didn't make any mistakes on there
Oh! I just remembered - If they are in the same directory as the file you just have to put the name of the picture
Based on this picture you may get an ideia
|