Where do I place the XlsxWriter file in Python? - python

I downloaded XlsxWriter zip file as I cannot use pip because of organisational restrictions. I extracted the zip file. Where inside the python directory should I place the XlsxWriter folder now ?

For most of the cases use pip to install Python modules. It is very easy.
Just do:
pip install XlsxWriter
And then in your script you can do the following:
import xlsxwriter
{...your code goes here}
If somehow you are not able to use pip, please follow this
After that close and re-open your IDLE and check.

Related

import in jupyter notebook to use a method from another file

I am using jupyter notebook. I have 3 jupyter source files written in python in a folder in the same directory: parser, preprocess, and temp. I am trying to import parser and import preprocess in the temp file so that I can use the methods written in those files.
Example: there is method named extract in parser file. I want to use that from temp file. How can I do that?
The easiest way is to change the files you need to import as py files. As an example, parser.ipynb can be converted to a python file parser.py, and you can import it from another notebook file. If you want to use a function named extract() from parser.py, just import
from parser import extract
You can use pip for installing packages. Open command propmpt (cmd) and type this below command
pip install preprocess
You can run pip install preprocess from the terminal (or CMD, if you are using Windows). Alternatively, you can run ! pip install preprocess from Jupyter Notebook itself, which will do the same thing. You may need the second one if you are working on Google Colab.

How to unzip .rar file with Python and patoolib

I need uncompress .rar file in Google Colab with Python3. First I tried to do localy in MacOS.
I have installed Patoolib package:
pip install patool
and unrar to unzip .rar files
brew install unrar
Then, In my python script I do:
import patoolib
patoolib.extract_archive("data_2/Peliculas.rar", outdir="/data_2")
and I get the following error :
PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z),
I need to configure Patool to use unrar but there is no documentation available. Somebody knows how to solve this error?
My issue was solved by simply adding my Winrar directory to my Path (in system environment variables). Made the horrible mistake of assuming it was set up by default (because why wouldn't it, it's already on the contextual menus right?), but that was not the case.
Hope this helps whoever reads this

Networking a .py file, with a .bat and .ini

Here is my problem :
I wrote a python script which works,but only on my machine (when I run it in my interpreter).
I also wrote .bat and .ini file (as I already did for other scripts which work), and when I run the .bat, it says :
import xlsxwriter
ImportError: No module named xlsxwriter
(The other batches I wrote for ohter scripts works well)
xlsxwriter is a new package I installed for this script (I installed in my interpreter (pyCharms))...
so why my batch doesn't work while my script does ? Do I have to dwnld/install the package/module somewhere else ? Where ?
When the problem is fixed, I'd like to share my .py ,.bat, .ini files with my colleagues so they can run the batch as well. What will be the steps ? Will they have to install/dwld the package as well ?
Yes, xlsxwriter must be present on any machine on which you want to run your script. The easiest way to install it on the host is with pip:
$ pip install xlsxwriter
You can also include a requirements.txt file with your script that includes xlsxwriter in it, and users can run the following:
$ pip install -r requirements.txt
More on pip and distributing packages that have 3rd party dependencies: https://pip.pypa.io/en/stable/

Install a package that is only one Python file and has no setup.py

How can i install a python package that does not have a setup.py file to call. I want to install a package that it happens to be only a .py.
Do i just save it as a .py and put it somewhere in the directory and then import it?
For example the zipfile package and the ElementTree XML parser
P.S.: I have Python-3.x
Edit: As said in the comments, these packages come with Python 3 so you should not install them manually (and certainly not the 2.7 versions). I let my answer bellow for people wanting to install custom package.
On a python interpreter, if you run:
>>> import sys
>>> sys.path
You will see a list of folder where your python executable search for module. You can put your file either in the site-packages folder or the lib folder.
Just put the file somewhere in PYTHONPATH.

Python import library from tar.gz?

I am working on a box which I don't have root access. However, there is a folder /share which would be accessed for everyone to read and write.
I want to figure out a way to put python libraries so that everyone could access and use them.
I figured out that I can put the egg file in the /share/pythonLib folder and in the python script.
import sys
sys.path.append("/share/pythonLib/foo.egg")
import foo
and it would work for everyone, however, I am not sure every library has egg version. For example, I am trying to install BeautifulSoup4 , however, there is only tar.gz file and I am not sure if it would be possible to convert to egg and ..etc.
OR! I am wrong right at the BEGINNING, and there are indeed some pythonic magics like below:
magicadd /share/pythonLib/foo.tar.gz
import foo
tar.gz is the source code of the library. You should unpack it, and you will find a setup.py script inside. Run:
python setup.py install --prefix=/share/pythonLib
This will create:
/share/pythonLib/lib/python2.7/site-packages/
In your scripts append that path to sys.path and everything should work fine.

Categories

Resources