I use rtorrent on ubuntu that download folder with rar files inside.. And I want to automatically run a script that unrar, maketorrent and other things to that unrarred file. My question is.. How can i get the dirname of the directory just downloaded? It s always different so I cant use a Variable or something like that. For now, i am downloading everything to /X and extract /x/*.rar to /X2. But its a very ugly way because i have to always delete everything in /X before starting a new download or everything will mess up.
I actually have the name of the directory Which, using irssi, is stored in a variable $releasename, but thats another program, i dont think i can import it to python.. Or maybe Yes, i don't know..
Related
I am working on a python project that depends on some other files. It all works fine while testing. However, I want the program to run on start up. The working directory for programs that run on start up seems to be C:Windows\system32. When installing a program, it usually asks where to install it and no matter where you put it, if it runs on start up, it knows where its files are located. How do they achieve that? Also, how to achieve the same thing in python?
First of all, what do you mean by "their files"? Windows applications can store "their files" in multiple places (including but not limited to %CommonProgramFiles%, %ProgramData% and %AppData%).
That being said, the common location for simple applications and scripts is to use the same directory as the .exe (or script).
In Python there seems to be multiple ways to find this path, this seems to work nicely:
import os
print(os.path.abspath(os.path.dirname(__file__)))
See also:
How do I get the path of the Python script I am running in?
How do I get the path and name of the file that is currently executing?
If you plan to consume local files that contain raw data or processed data, defining a default directory or a set of directories can simplify your implementation, for example:
Place your data files under a specific set of folders in C:\ or place your files under the F:\ folder, that can be a part of your on premisses file system
Based on where your Python application is located, you'll need to use relative paths or a library to help you to locate these files.
Here are some examples:
os.path
pathlib
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
So I'm trying to share my PyQt project. When I download the zip file and extract it, it looks like
If I run app.py from CMD, it will run the app, but without the icon file which is inside of that folder. Inside of the code I do need that file and point to it, so I'm not sure why it doesn't find it automatically. It seems that without it the app doesn't work properly. I was wondering if there's a work around for this issue.
Here is how the app looks when I "open folder" in my IDE:
Here is how it looks when I simply open the .py file, in that same folder:
Anything related to the icons (basically all notifications) are not working when I run it like that.
I'm not sure what why it behaves like this, but I'd like to be able to share the code for anyone to use without them opening the whole folder.
Eventually, I ended up changing how I'm using the paths.
I added this
dirname = os.path.dirname(__file__)
iconFile = os.path.join(dirname, 'icon/icon.png')
So now I'm using iconFile as my path. Seems to fix the issue
I am a novice python user and I use Atom to code in python. Sometimes, I use python 'os' module to get the working directory and in some cases, I have to navigate through directory/folders to get to where I want the code to run. e.g. say my starting working directory is "C:\Users\XYZ" and I want to change directory to some folder named "ABC" in some directory path under D:. Currently, I have to open an explorer window to figure out where the 'ABC' folder is and then copy paste the directory in Atom and swap '\' with '\' and use os.chdir function. Is there an easier way or some Atom package where I press the first letter of the folder and it gives me autocomplete suggestions? I tried os.listdir() but copy paste using that is too cumbersome. I know that I can just create my file in that directory to start with but I want to learn if I can navigate through folders the way using autocomplete suggestions.
Any help would be great.
This is not exactly what you want but may help you. There is an Atom extension "platformio-ide-terminal" which when run will open a regular bash shell at the bottom of your Atom window. Using this you can easily move around your directories using unix commands. Hope this helps some.
Hi!I made a chess engine in python which i then compiled to .exe using py2exe. The problem is that it doesn't look very neat when i have all the strange files gathered together in the same folder (dist). I'd like to make a new folder inside the dist folder that contains all the helper files, so all my dist folder contains is the folder holding the helper files and the main launch application. However, i can't simply copy the helper files to a new folder, as the computer doesn't find them then and raises an error.
How can it be solved? Also, i'm using inno setup to make an installation, but i can't figure out how to find a solution there, either.
Thank you very much!
There is a feature in the configuration of py2exe that allows you to bundle all the Python files in a single library.zip file. That would considerably reduce the amount of files in the root directory, but there will still remain some files, regardless of all that.
These files are generally DLL files, at least from what I saw with GUI applications. You cannot remove these, because they are required to launch the application. A workaround to this problem is to create a batch file that will run the actual program which can be in child directory. The point is that these files should either be in the same directory as the executable, or the current working directory, or a path in the PATH environment variable. At least it's the case of most of these. Another approach might be a batch file which will modify the PATH variable or cd to another directory and run the file afterwards
I never tried to do it, so it might break some things for you. Anyway, IMO the best approach is to create an installer and add shortcuts and you won't have to bother with the user messing with these files.
Try using pyinstaller instead. It's easy to use, and will compile your PythonLib and all necessary python files to a stand alone EXE. So you don't have to worry about the having a mess of files in your dist file. (just one single exe).
And if you have other external files, such as databases, text files, csv's. etc... you can set them up to deploy in exactly the fashion you want from the inno setup [Files] section.
I wrote a detailed explanation on this yesterday, so check out this link:
https://stackoverflow.com/a/13259452/1339024
--Edit--
*Make sure you use pyinstaller 1.5 , as the 2.x version doesn't exactly work the same