Python Module Question - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python Module Question (/thread-296.html) |
Python Module Question - ATXpython - Oct-05-2016 I've created a script that I'd like to share with some coworkers. This script requires one module to be installed. I was able to successfully do this via pip on my work computer, however my coworkers cannot use pip. They continuously get a lengthy error in the command prompt window. I didn't have much time to look over the error, however I suspect that its because their user accounts are not administrator accounts on their machines. I know they can create/edit directories without any issue - So here is my idea / question: Could I simply copy all of the files that are installed on my machine via pip, and drop them into the same location on their machines? And if that will work, where is everything stored once its installed via pip? With a quick search, it looks like the path is: Program Files > Python > Lib > site-packages Is that correct? RE: Python Module Question - metulburr - Oct-05-2016 The easiest solution would be to create an exe. This puts the interpreter in, any 3rd party libs, etc. Its the only 100% solution that the client can run the program with the least amount of errors, and knowledge on their part. http://www.py2exe.org/index.cgi/Tutorial What program is it? What 3rd party libs are you importing ,etc. RE: Python Module Question - ATXpython - Oct-05-2016 I appreciate the suggestion. I'll do some research on doing exe files. Im trying to avoid that, as Id have to jump through some hoops to get something like that installed on these various machines. Is my proposed method not possible? RE: Python Module Question - metulburr - Oct-05-2016 Quote:This script requires one module to be installed.What module is this? You can just add this module to your package and import it as normal instead of having everyone install that module. RE: Python Module Question - Crimson King - Oct-05-2016 Do they have virtualenv installed on their machines? They could create a virtual environment and use pip to install your module (and any other requirements). RE: Python Module Question - ATXpython - Oct-05-2016 metulburr - The script needs access to xlrd. I dont have experience with packaging up a module like you suggested. Is there a good tutorial you can point me to? Crimson King - no virtual environtments on these machines :( RE: Python Module Question - metulburr - Oct-05-2016 (Oct-05-2016, 04:50 PM)ATXpython Wrote: I dont have experience with packaging up a module like you suggested.You would just download the module and put it in the same directory as your script that requires it. Then zip the directory and give it to people. They will have the module since you zipped it in with your script. When your scripts imports that module it will import it from the same directory. I am assuming your scripts are being ran on windows? If linux, you can just download the module from the repos via your script beforehand (of course you could do this in windows too from the source)
RE: Python Module Question - ATXpython - Oct-09-2016 metulburr - I appreciate your time on this! The program will run on Windows workstations. So packaging this all up into the same directory as the script seems like it would work out pretty well. I apologize for the noob questions on this, but I still don't quite follow how this would work. For xlrd, would I simply download the wheel file from pypi and put that in the same directory as the script, or is there some unpacking that needs to be done? I've only ever install modules via pip, I've never messed with the source files or anything like that. Any additional information you could lend would be greatly appreciated! RE: Python Module Question - metulburr - Oct-09-2016 Im not aware of that lib, how they handle it, etc. a wheel is just compressed file...if you change the .whl extension to a .zip, then in windows you can unzip it and get the contents. An example that i dont have that module installed metulburr@ubuntu:~/Downloads$ python Python 2.7.12 (default, Jul 1 2016, 15:12:24) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import xlrd Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named xlrd >>> exit()downloaded wheel file rename wheel file to zip metulburr@ubuntu:~/Downloads$ mv xlrd-1.0.0-py2.py3-none-any.whl xlrd-1.0.0-py2.py3-none-any.zipunzip zip file metulburr@ubuntu:~/Downloads$ unzip xlrd-1.0.0-py2.py3-none-any.zip Archive: xlrd-1.0.0-py2.py3-none-any.zip inflating: xlrd/biffh.py inflating: xlrd/book.py inflating: xlrd/compdoc.py inflating: xlrd/formatting.py inflating: xlrd/formula.py inflating: xlrd/info.py inflating: xlrd/licences.py inflating: xlrd/sheet.py inflating: xlrd/timemachine.py inflating: xlrd/xldate.py inflating: xlrd/xlsx.py inflating: xlrd/__init__.py inflating: xlrd/doc/compdoc.html inflating: xlrd/doc/xlrd.html inflating: xlrd/examples/namesdemo.xls inflating: xlrd/examples/xlrdnameAPIdemo.py inflating: xlrd-1.0.0.data/scripts/runxlrd.py inflating: xlrd-1.0.0.dist-info/DESCRIPTION.rst inflating: xlrd-1.0.0.dist-info/metadata.json inflating: xlrd-1.0.0.dist-info/top_level.txt inflating: xlrd-1.0.0.dist-info/WHEEL inflating: xlrd-1.0.0.dist-info/METADATA inflating: xlrd-1.0.0.dist-info/RECORDThis unzipped all contents into my Downloads directory. All you need is the single xlrd directory metulburr@ubuntu:~/Downloads$ cd xlrd xlrd/ xlrd-1.0.0.data/ xlrd-1.0.0.dist-info/So copy the xlrd directory to your script wherever that is calling it (or in the root directory of your package). an example of importing it from my Downloads directory metulburr@ubuntu:~/Downloads$ python Python 2.7.12 (default, Jul 1 2016, 15:12:24) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import xlrd >>> exit() metulburr@ubuntu:~/Downloads$ python3 Python 3.5.2 (default, Sep 10 2016, 08:21:44) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import xlrd >>> exit() metulburr@ubuntu:~/Downloads$Note the reason its better to package this into an exe with the interpreter is if (for some reason) the clients are using an older interpreter which causes an error with this module, etc. You can insure that it runs without errors. Where this method is not so 100%. RE: Python Module Question - ATXpython - Oct-09-2016 metulburr - Thanks for taking the time to spell that out for me - so incredibly helpful! Much appreciated! |