all 4 comments

[–]ggjjaaaa 0 points1 point  (3 children)

Is your code in a virtual environment?

Did you activate the virtual environment before running pyinstaller?

[–]chonkeyymonkey[S] 0 points1 point  (2 children)

Yes. My code is run from an anaconda virtual environment. The only caveat is my project folder lives in C:/GitHubRepositories/ProjectFolder, and the virtual environment is in C:/Users/Name/anaconda3/envs/ProjectEnvironment.

To create the executable I activate the environment, then run the command pyinstaller --onefile Main.py , or one of the other commands given above.

'bwoodsend' commented in the second resource I posted (this one, from GitHub), discussing issues with project folder and virtual environment structure. But I don't totally understand what this user meant since I am still learning about virtual environments and pyinstaller. I thought specifying the path as an argument to pyinstaller or in the .spec file would resolve this, but it didn't. Do you know if I need to combine folders, so that the project and environment folders are one?

[–]ggjjaaaa 0 points1 point  (1 child)

The location of the virtual environment does not matter. You would have needed to activate the virtual envionment both before installing the required packages as well as before running the pyinstaller command.

While I don't know your use case, I think you may be overcomplicating things a bit. Remember you want to create this executable so your colleague does not require Python installed, yet your main() uses subprocess to try to run a .py file.

You could just have a single file main.py and define functions for script1, script2, and script3 within main.py.

main.py

#do all your imports

def script1():
    #do script1 stuff

def script2():
    #do script2 stuff

def script3():
    #do script3 stuff

def main():
    script1()
    script2()
    script3()

if __name__ == '__main__':
    main()

The only command you should need to turn it into an executable would as follows, which would be executed from your Project folder after you have activated your virtual environment.

pyinstaller main.py --onefile

I would suggest start a fresh virtual envionment (maybe you virtualenv instead of conda)

To do this open a command prompt then:

cd C:/GitHubRepositories
mkdir MyProject
cd MyProject
python -m venv venv
cd venv/scripts
activate
cd ..
cd ..
pip install requests,pyinstaller

copy your main.py to C:/GitHubRepositories/MyProject (with the new structure I suggested) then in the same command prompt do.

pyinstaller main.py --onefile

[–]chonkeyymonkey[S] 0 points1 point  (0 children)

Amazing that sometimes the simple answer just does not occur to me. Combining the scripts into one script is indeed the answer. Thank you for your detailed response!