0

Essentially want to send a script to my friend to go over. He has python installed on his computer, but doesn't specifically have 'pyinputplus' - a key component of the program.

Is there a way that I can send this script to him without him installing pyinputplus? Or whether I can effectively insert 'pip install pyinputplus' into the code and have it execute when he runs it? I had also considered making the script an executable, but didn't think that would help.

Relatively new to this, so apologies for my naivety.

Thanks.

MCLyonzo
  • 1
  • 4
  • can't he install it? or you can try something import subprocess ```` import sys subprocess.check_call([sys.executable, "-m", "pip", "install", package])```` – Pdeuxa Jan 14 '21 at 09:30
  • 1
    You may compile it into .exe/.app/whatever on linux using pyinstaller or make command run when script started using subprocess module. – Rocket Nikita Jan 14 '21 at 09:30
  • 1
    https://stackoverflow.com/questions/5458048 – mvp Jan 14 '21 at 09:33
  • 1
    Related: https://stackoverflow.com/q/89228/14191957 https://stackoverflow.com/q/12059509/14191957 – Rocket Nikita Jan 14 '21 at 09:33
  • 1
    Also take a look: https://stackoverflow.com/q/46419607/14191957 – Rocket Nikita Jan 14 '21 at 09:35
  • 1
    Can’t stop finding links! https://stackoverflow.com/a/36761640/14191957 – Rocket Nikita Jan 14 '21 at 09:37
  • Thank you for your replies, I was unsure how to word the question - and typing it a few different ways didn't bring up related questions either. I will check these out ! – MCLyonzo Jan 14 '21 at 09:49
  • 1
    Does this answer your question? [How can I make a Python script standalone executable to run without ANY dependency?](https://stackoverflow.com/questions/5458048/how-can-i-make-a-python-script-standalone-executable-to-run-without-any-dependen) – Rocket Nikita Jan 14 '21 at 09:49
  • That last link is brilliant! Thank you so much for your effort in finding those links – MCLyonzo Jan 14 '21 at 09:55

2 Answers2

0

indeed you can give him directly the source code of the librairy. Using in python the command sys.path you can found all folders where python will search for theses librairies. Just give him the folder and let him place it inside a result of his sys.path.

Vincent Bénet
  • 542
  • 2
  • 14
0

The best way to work with someone else on a script is to use a repository. You can create a free one on github for example.

You will put your code there with some git command OR using a GUI to do it (you can download for free SourceTree). This tool will allow you to send your code (files) on the repository and to your body to get it back.

Then you can add a requirement.txt file that will include all the dependencies.

To generate it, just run the command :

pip freeze > requirements.txt 

This file will contain all the dependencies you need to run the script.

Your body, then can download all the dependencies easily by running :

pip install -r requirements.txt

But actually, you should also use a virtual environnement for each of your project. This will allow you to not mix up all the dependencies of all the project together.

If you want to learn more about it, check this page : https://blog.usejournal.com/why-and-how-to-make-a-requirements-txt-f329c685181e

  • You can also make the requirements.txt file manually and send him with the script. But anyway, he will need to install python. Each line is linked to a dependency and the dependency version. In your case : pyinputplus~=0.2.12 – Nicolas Julémont Jan 14 '21 at 09:45
  • This is an excellent answer, thank you. The person in question is more just running the program to see if he encounters any errors - and is not very tech savvy, which is why I'd thought of inserting it on my end within the code – MCLyonzo Jan 14 '21 at 09:53