Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Module Question
#1
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?
Reply
#2
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.
Recommended Tutorials:
Reply
#3
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?
Reply
#4
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.
Recommended Tutorials:
Reply
#5
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).
Reply
#6
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 :(
Reply
#7
(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)
Output:
metulburr@ubuntu:~$ sudo apt-cache search xlrd [sudo] password for metulburr: python-xlrd - extract data from Microsoft Excel spreadsheet files python-xlwt - module for writing Microsoft Excel spreadsheet files python3-xlrd - extract data from Microsoft Excel spreadsheet files (Python3 version)
Recommended Tutorials:
Reply
#8
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!
Reply
#9
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.zip
unzip 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/RECORD 
This 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%.
Recommended Tutorials:
Reply
#10
metulburr -


Thanks for taking the time to spell that out for me - so incredibly helpful!

Much appreciated!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  datetime module question jacksfrustration 10 1,609 Jan-12-2024, 04:54 AM
Last Post: deanhystad
  Module not found question sighhhh12 0 1,448 Sep-09-2022, 05:43 AM
Last Post: sighhhh12
  Question on subprocess module. knoxvilles_joker 3 2,622 Apr-11-2021, 12:51 AM
Last Post: knoxvilles_joker
  keyboard module question DPaul 0 2,110 Mar-23-2021, 04:22 PM
Last Post: DPaul
  Module googletrans 2.4.0 Question hlhp 0 2,552 Jun-17-2019, 03:50 PM
Last Post: hlhp
  Question about the Random Module Exsul 1 1,969 Mar-13-2019, 02:06 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020