Due to a source control folder structure that is out of my control I have found myself in a situation where I need to keep my source python files in three separate locations up-to-date at all times. I am looking for the cleanest solution to accomplish this without having to resort to hacking it together.
I have all of my primary python source files and my Visual Studio 2012 Python Tools project files in a folder that is not published to the end user, but is managed via source control.
I have all of my python files updated into a separate folder that is published to the end users. Files contained in this folder are not ever executed, only used to publish into final builds.
I have a local folder that these python files will end up in if I download a published build. Unfortunately when executing the main application from the published build, this is the folder that the python files will be executed via.
Obviously this is a simplified explanation of the problem. However my goal is to cleanly be able to save a file while editing in Visual Studio 2012 Python Tools, and have it distribute to PublishFiles, and DestinationFiles. Very similar to how in any C++ project you would have an output directory.
My first reaction to this question would be to not work in this fashion, unfortunately I do not have any control over this situation, only need to develop a solution to the problem.
Thanks!
Related
I have a Tkinter app that uses images included in the same folder as the .py file. pyinstaller script.py produces an executable that runs but does not open any windows. This is because it is looking for images that don't exist in the same subdirectory. When I copy the important images to the dist folder Pyinstaller creates, the application runs correctly.
However, I would like to have a single executable that I can share with other users that doesn't also require them to have the images stored. The images should be bundled with the software somehow, like how commercial software (usually) doesn't require you to download assets separately from the program itself.
Is there a way to bundle Python programs and the assets they use into single-click applications?
Note that I am using Python 3 on Linux Mint. I am also something of a novice, so don't be surprised if I'm missing something obvious here.
It appears I've solved my own problem.
Instead of having the images included in the same folder as main.py and using the resulting short relative filepath to reach them, install the images in an appropriate space in the system directory tree (I used /home/$USER$/.$PROGRAMNAME$/) and have the program access the files using the absolute path to that directory. This will allow you to copy the program anywhere on your computer you want and have it run without a problem.
However, if you want to share it with someone else, you'll need to also include an installation script that places the assets in the correct directory on their computer.
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
I have finished my python project and now want to transfer the project into one file, so a user can just double click it and doesn't have to compile it first.
Therefore, I wanted to know if this is possible with python.
I 've read that you can convert a single python script into an executable file using pyinstaller. But in my case I have many files in different folders and I want them to be include in the executable file because otherwise the programm doesnt work.
I also tried this via the auto-pyto-exe converter (https://github.com/brentvollebregt/auto-py-to-exe) but I didnt got the results I wanted.
Therefore, my question is, how can I convert my visual studio python-project with many different files and folders into one executable file, so a user can just double click the file to start it?
Edit
In the other folder are also .py files like some FileImport.py or View.py. I separated these files that the whole project looks cleaner.
The Folder structure looks as follows:
-Views
---MainView
---UpdateView
---AnotherView
-Controllers
---MainViewController
---UpdateViewController
-Model
---MainModel
I found the solution. As it appears the pyinstaller can find all dependencies when you compile your script via pyinstaller myscript.py. PyInstaller creates three different folders where all necessary files are located. In the dist folder one executable is located which can be used from computers without python installed.
I hope this helps somebody who has the same problem.
I have setup a python project in Visual Studio 2017 Enterprise (Version 15.4) as part of a mixed-project solution also containing various C#(.Net 4.6.2, .Net Core 2.0 and Xamarin) projects. During the build I want to generate several .py source code files using some self-written C# tool which is also part of the build. Additionally all .py files listed as "Compile" items in the .pyproj file should be compressed into a .zip file and written to some output directory.
In my .pyprof MSBuild file I craeated two "custom build step" targets like so:
<Target Name="MyPreBuildStep" BeforeTargets="Build">
Call self-written py-Code generator
</Target>
<Target Name="MyPostBuildStep" AfterTargets="Build"
Inputs="#(Compile)"
Outputs="$(OutputPath)\$(PythonProjectName).zip">
<Zip ZipFileName="$(OutputPath)\$(PythonProjectName).zip"
WorkingDirectory="$(MSBuildProjectDirectory)\..\" Files="#(Compile)" />
</Target>
The Zip Task being imported from the MSBuildCommunityTasks.
If I right-click on the project in Visual Studio and hit "Rebuild" everything works fine. The py-code is generated in advance and all #(Compile) items are put into the .zip file.
Unfortunately the normal "Build" NEVER invokes the above targets. So with my current setup, I can build my 40-projects containing solution just by hitting "Build" BUT the python projects needs an extra-invitation by hitting "Rebuild". Very annoying.
I tried to investigate the contents of "Microsoft.Python.Tools.Web.targets" and "Microsoft.Python.Tools.targets". Somewhere inside these files a comment says:
"The Build target is invoked as part of the Publish phase."
hmmm.
Can somebody tell me how to specify some simple custom build steps in a .pyproj that just work during a normal "Build"?
Thank you.
Build is only invoked when required, and this is determined based on comparing the last modified times of input and output files.
Mostly these are automatically collected, but in your case the output file is not recognized and so does not influence whether it needs to be built. (If you inspect Microsoft.PythonTools.targets and find the BuiltProjectOutputGroup and SourceFilesProjectOutputGroup targets, these are the ones that provide the files.)
In this case, you should only need to add the ZIP file as an output file so that it is checked. You can do this with:
<ItemGroup>
<OutputFiles Include="$(OutputPath)\$(PythonProjectName).zip">
<Visible>false</Visible>
</OutputFiles>
</ItemGroup>
Note that it needs to be available without running the build target, so you have to be able to compute the path statically, but now the project should rebuild if this file does not exist or any of the source files are newer than it.
I'm relatively new to python and used to C, and I'm trying to find a way to possibly compile several .py files in a directory together as one file. Some of the methods I've seen were to make an egg or bundle them up as a zip file and run it with 'python foo.zip,' but I'm pretty restricted on those options.
The .zip method is closest to what I'm after but what I need is more along the lines of importing that file in the main script and not as an argument to the interpreter.
I have to run this code on several machines and would rather not have to copy a whole folder of modules with it, and would also rather not have to paste all of my code into one file.
Caveats: I'm running a pretty old version of python (2.4.3) on machines that are cut off from the Internet and that I don't have physical access to, so I can't install other modules. I would have to be able to pull it off with old vanilla python.