How to install something that read excel files in python 3.3 - python

I am new to python and I need to read an excel file in pyscripter. I understand that I should
import xrld
in Python and then use:
book = xlrd.open_workbook(os.path.join(file_source,file_name +".xlsx"))
to open and read the excel file.
However, I just don't understand how to install this module 'xrld'. I have looked on several websites and even on stackoverflow itself, but I just don't understand anything from the explanations that are given. I just don't understand how to install 'easy install' or 'pip' (or understand what these things are in the first place) or understand how to install anything else I need to read an excel file for. So far I installed a file called 'setuptools-36.01.1' from https://pypi.python.org/pypi/setuptools which should contain something I could use for running, but I just don't understand what to do.
I thereby must admit (and think it is clear by now) that I am a real noob when it comes to programming or computers in the first place.
Can someone please help me by explaining in plain English what exactly to do in order to read an excel file in python. I have Python 3.3.2 and use Pyscripter to run my simulation.
Your help would be really appreciated!

EasyInstall (easy_install) gives you a quick and painless way to install packages remotely by connecting other websites via HTTP.
Pip is a package management system used to install and manage software packages, such as those found in the Python Package Index. Pip is a replacement for easy_install.
Since you have installed the setuptools, easy_install will be already present in your system.
So just run easy_install pip in the command line to install pip . Then pip install xlrd for installing xlrd.
example code:
import xlrd
workbook = xlrd.open_workbook('C:/User/myaccount/Book1.xls')
worksheet = workbook.sheet_by_name('Sheet1')
print worksheet
Please go through this link-Reading Excel file using Python XLRD for sample codes for reading data from excel files in python.
Hope this helps you..

Related

Bigquery import asks for pyparsing in shell run

I get this error "ImportError: The 'pyparsing' package is required" after trying to run .py file with from google.cloud import bigquery line. Import was working before and is still working in the Jupyter Notebook or in Ipython.
I looked at existing options here and tried:
pip install pyparsing
downgrade setuptools
uninstall pyparsing and setuptools and installing them back
uninistall and purge pip and install it back
Does anyone have suggestions? Thanks
I found the problem. It is silly, but happens to me from time to time. Do not name files in your project like - html.py =) . It was in one of the folders of my project. Really annoying, but nevertheless, hope it will help someone. Maybe you have same problem with different file name, but look up for files with common use names!)

how to install numpy on mac [duplicate]

This question already has answers here:
How to install NumPy for python 3.3.5 on Mac OSX 10.9
(3 answers)
Closed 6 years ago.
I'm trying to install Numpy on my mac so i can practice doing some programming for data science. However i have no idea what i'm doing when it comes to downloading software and btw my knowledge of software instillation in general is terrible (i'm more of a pure mathematician). If it isn't as simple as hit download and it works (as it seemed to do with windows) i'm finding myself getting stuck.
I have python 3.5.1 downloaded on my mac. So the book i'm going through at the moment when talking about arrays starts by saying >>>import numpy, in the command prompt. Thinking it would just be as easy as that i tried it, but obviously it wasn't that simple because i haven't downloaded it. Anyway then i looked into downloading numpy, i downloaded a folder in my downloads called numpy.1.11.0 and copied and pasted it into my desktop. I went back to the idle and typed >>>import numpy again, and again it didn't work.
I'm so confused as to what to do now, i've looked at some older posts but they haven't helped, i've also downloaded an open source package called anaconda (something mentioned in the other posts) which i think has everything (data science related) on it but i have no idea how to use it. Do i create python scripts in anaconda? Do i create the scripts before and some how run them in anaconda?
I'd really appreciate any help regarding how to get numpy installed or perhaps how to start using python in anaconda (or both). I've found myself getting lost in all the jargon in the other posts, a simple step by step approach i.e "first click this", "then install this" would probably be best suited to me, if anyone knows where i can find instructions in this form i'd very much appreciate it.
Thanks for the help!
Edit: Thanks to everyone for the help it has been great, in particular i tried pip3 install numpy in the command line. Now i can import numpy in the python idle. If i want to use it in a script file (i'm using text wrangler for this) would i just import numpy as usual?
In addition i started playing around with anaconda and using the spyder package this also let's me run python scripts and allows me to import numpy.
Go to your terminal and run the following command:
pip3 install numpy
If that gives you permission or IO errors try using sudo
sudo pip3 install numpy

Python 3.5.1 : How to check whether openpyxl package exist and if it does not exist how to download and install it "within" the script?

I started writing python codes two weeks ago and until now I have manipulated some excel data after converting it to txt file. Now, I want to manipulate excel data directly, so I need to install openpyxl package. However, my script will be used in many different places and computers (Note that: all of them use either OS X or a Linux distrubution) which might (probably do not) contain openpyxl package installed. I want my script to check whether this package exist, and if it does not exit, then download and install it.
For that purpose, as I searched and found that I could check the existence of the package by first importing the pip module and then pip.get_installed_distributions() method. However, I am not sure whether I am in a wrong way or not. Besides, I have no idea how to download and install openpyxl package "without leaving the script".
Would you like to help me ?
You are getting ahead of yourself by trying to solve a deployment problem when you don't have the software to deploy.
Having a script trying to manage its own deployment is generally a bad idea because it takes responsibility away from package managers.
Here is my answer to your question:
Build your software under the assumption that all packages are installed/deployed correctly. I recommend creating a virtualenv (virtual environment) on your development computer, using pip to install openpyxl and any other packages you need.
Once your software is built and functional, read up on how to deploy your software package to PyPi: https://pypi.python.org/pypi. Create your package by defining openpyxl as a dependency, ensure your package can be installed/run properly (I recommend adding in tests), then deploy to PyPi so anyone can use your software.
If you want to add a nice layer of validation in your script just in case, add the following to your main method:
#!/usr/bin/env python3
import sys
try:
import openpyxl
except ImportError as iE:
print("Python Excel module 'openpyxl' not found")
sys.exit(1)
... rest of script ...

Import error for openpyxl

I'm very very new to coding and I'm having an issue importing openpyxl into my python program. I imagine the issue is due to where I have it saved on my computer.
I've downloaded other libraries (xlrd, xlwt, xlutils) before and just saved them in my: C:\Python27\ArcGIS10.1\Lib, or C:\Python27\ArcGIS10.1\Lib\site-packages, or C:\Python27\ArcGISx6410.1\Lib, or C:\Python27\ArcGISx6410.1\Lib\site-packages directories and python has been able to "see" them when i import them into a script.
I've done some trolling on the web and it looks like I may be performing the "installation" of openpyxl incorrectly. I downloaded "setuptools-5.7" in order to try to run the setup.py script contained within the openpyxl library, and so far I haven't gotten that to work out.
Since I'm so new to python, I don't really understand some of the other stuff I've been finding about how to correctly install the library, like "pip install" etc.
If anyone has any ideas about how I can install or save or locate the openpyxl library in the easiest fashion (without using other programs that I don't already have), that would be great!
Your import is probably incorrect.
It needs to be.
from openpyxl import workbook

Has anybody been able to install PyWeka?

I need to install in python 2.6 or 2.7 for windows the library PyWeka0.3dev, It says it requires setuptools, which I installed but then they told me it was a deprecated instalation library and I installed distribute, then I downloaded the PyWeka compressed package and each time I try to install it neither with setup.py nor with easy_install (where it says something like no module ez_setup). Can anybody give me a clue about how to do this?
As mentioned to you via Aardvark (yes, I am omnipresent), the module in question is broken. You can't easy_install it. It's a bug in PyWeka.
You can download the file from PyPI, http://pypi.python.org/pypi/PyWeka/0.3dev, and unpack it.
In the file setup.py, remove the following two lines:
from ez_setup import use_setuptools
use_setuptools()
And install it by running
python setup.py install
You need to have installed numpy and NamedMatrix (which has the same bug as PyWeka) first.
However, you mentioned you are on Windows. I strongly doubt that PyWeka will work on Windows. There are some Unix specific code in it.
And I still really want to know why the authors are reading files by calling cat from subprocess. That seems pretty pointless and is together with the broken install, good enough reason for me to keep far away from that module. I suspect it's authors simply have no idea what they are doing.
That, or they are geniuses.
A punk/goth approach to programming probably has the right to be..
To get the C-compliation part to work on windows you either need (1) to have Visual Studio of the same version that was used to compile the python version you are using, or (2) mingw which is a bit trickier to set up.

Categories

Resources