Place Text Files in another location - selenium - python

Currently my program is using txt files (filled with data) that are located in the Desktop. I am going to be sending this out to users and the text files are going to be included in a installer. When installing I don't want these files to crowd the users desktop. Any ideas on this??

Kunwar, this is a somewhat subjective question, so this essentially is a subjective answer.
This is really about packaging. You've not provided any info on what your package lookslike, but in principle, why not just put the text files in the directory with your program?
your_program/inputs/*.txt
Then they will always be available to your tool. You can find the current location of your script within the script itself and build the path to the input file, no matter where the users have stored the script on their machines.

Related

Pycharm using two projects to run

So I am trying to submit some coursework for university, but when I compress the project and send it to my friend, he cannot run it.
I noticed at the top of the console there is this line
"/Users/maxculley/Desktop/PART 2/bin/python" "/Users/maxculley/Desktop/UNI WORK/YEAR 3/Data structures and algorithms/Coursework 1/PART 2/CODE/main.py"
I located the files on my desktop and it seems as though I can only run this if the project has these files at that file path.
Anyone know why the project is using these files from two project?
FIXED -- Realised I didn't need to compress the whole folder, just the python files, the interpreter is what was causing the issue as this is what was located on my home screen

how to persist/store data in executable compiled with pyinstaller

I need to locally store some basic data the user inputs into my exe. The program was compiled using pyinstaller and was previously making use of the os open method of saving data to txt files. It is my understanding that macOS(my OS although cross-compatibility with Windows would be great) locks executables so that they may not make any file changes. The program currently does save the data, but when the executable is run again the old data is no longer accessible.
It seems obvious that apps store things locally all the time, how can data be persisted specifically within the python/pyinstaller combination?
Apologies if this is a simple question, it definitely seems simple but I can't find documentation for this anywhere.
You can use
os.path.expanduser('~user')
to get the user home directory in a cross-platform manner, see How to find the real user home directory using python?
Your application should have write permissions in the user home directory, so then you can let it create and modify a data file there following How to store Python application data.

How to convert multiple python files to EXE?

I am trying to convert my python application to an exe. I have seen things like py2exe and cx freeze, but they only compile one single py file. Can anyone help me? Thank you
I currently use pyinstaller for building projects into single-executable files. These projects all contain multiple python (and some non-python) files that are all "built into" the exes.
That being said, even with multiple python files included, Marcus Müller is correct. There is one entry point for a given executable.
In summary, if you have multiple files as part of a single project, pyinstaller along with the other python bundlers will handle this scenario.
If you have multiple files and want them each to be their own executable file, you will need to treat each as its own 'project' and package each individually.
What platform(s) are you targeting? Can you describe the intended purpose of the files? Can you describe the intended usage of the files?
Posting an example of what you currently have, what behavior you are observing, and clarification on what is different between what you are expecting and what you are observing would definitely help others in guiding you towards the answer you desire.
Edit:
Well, I have a main python file that is referenced to a very brief config.py. The main file also accesses a few text files. Could I just combine the config and the main into one py file, and make that an executable, and will that executable still have access to the text files?
Your main python file would be your exe's entry point. If you import your config file into your main, pyinstaller should see the import and include it. On this line, verify your PATH environment variable, and insure your system knows where to find the bits it needs. If the text files are to be included as part of the built executable file, pyinstaller has the ability to include files into the build as well (example, include a database, a config, or a static data set). An example question describing including an icon file for a build: include-pyinstaller-icon
For example in PyInstaller, you can specify additional folders which should be involved in your executable file.

How to access "locked" files for backup program

I am trying to create a google drive like backup program using python that backs up to a Linux box that will further backup to an off site place tbd. I have ran into a few interesting coding and computer challenges in doing this.
The one I am working on right now has to do with "locked" files. So what do I mean by this? In windows 7 if you create a .txt file you can open it in notepad(any program) and at the same time you can open it in a python program. If you make a change in the .txt file and save the change but BEFORE closing it you can still open and see the changes in pythn. Now change the file to a .docx windows file and open it with word 2007. While opened in word you cannot access it with in python until the user closes it.
Now if you look at google drive, the desktop install not the web only variety, you can open a .docx file and change it. Once you save it but BEFORE closing google drive has already synched the file.
Google drive must have some sort of lower level access to the file than the simple python file.open() command.
So here is the question. Does anyone know of a way to access files in python in such a way as to keep me from having to wait for the user to close the file.
Edit 1:
Let me further explain. Once I have created an sqlite database that has all the files and directories I will then use the win32file.ReadDirectoryChangesW() function to monitor for changes. My problem stems from the fact that when setting up the application of first install/run it must catalog all files and files that are open in windows office are locked and cannot be cataloged. Is there a way around this?
Many backup tools use snapshots. Then, they'll copy the locked file directly from the snapshot rather than coping it directly from the filesystem. If you're on Windows you should check Windows VSS, see the Microsoft documentation for more details. Otherwise, if the filesystem you're on supports snapshots check its documentation as well.
Third party tools
You can use the subprocess Python module to run third-party tools which will take snapshots for you.
Microsoft VSS
In case you want to do it by yourself you might need modules from the Win32 API such as win32com module.
There is also on Github a project that seems to do the job: pyshadowcopy
Filesystem Snapshot
Depending on the filesystem features, you might find python modules or tools allowing you to take a snapshot.

Single EXE to Install Python Standalone Executable for Easy Distribution

I used Pyinstaller to create a standalone exe file for a PyQt project. I did not use the single file option because the exe that is created with the single file option takes too long to open. Therefore, Pyinstaller created a dist folder that contains a bunch of files including my program.exe file. I would now like to create a setup.exe file that will place the contents of my dist folder in the program directory and create a shortcut in the start menu and on the desktop. I want it to be super simple for the user. Maybe like the setup.exe files that you get when you download a program from CNET. I found Inno-setup, which looks promising. However, I do not know if there any special considerations because the program is a standalone program create from a python/PyQt program. Thanks! Anyone have experience with this task? Is there a program everyone is using for this task that I do not know about?
Inno-Setup or NSIS are probably the easiest to use. You just tell them what files to include and where to put them and then they will create a nice installer for you. I wrote a short tutorial on my experiences using InnoSetup that you might find helpful:
http://www.blog.pythonlibrary.org/2008/08/27/packaging-wxpymail-for-distribution/
Note that this tutorial was based around a wxPython app I wrote, but the concepts are the same.

Categories

Resources