- System Preferences -> Security & Privacy -> General tab -> unlock icon -> You can one time allow TKinter or allow software from anywhere
- install pip system wide
-
python get-pip.py
-
- Windows MSI Installer (2.7.10) - Python 2.7
- Need to check the install for all users box.
- Use 64 bit if you have it.
- If you use the 32 bit follow the instructions for getting pip on MAC.
- Set the environment variable
- win key -> <search 'thispc'> right click -> properties -> advanced system settings -> Environment Variables
- Create a new user variable 'PYTHON27_HOME' value: C:\Python27
- Create a new user variable 'PATH' value: %PYTHON27_HOME%;%PYTHON27_HOME%\Scripts
- win key -> cmd -> python -V
- Set the tkinter env variables in Fixes section at the bottom (If idle fails to start)
-
install virtualenv system wide
pip install virtualenv
-
create a new directory for your py201 files
-
create a virtualenv 'venv' in class directory
virtualenv venv
-
source venv
-
MAC
source venv/bin/activate
-
WINDOWS
venv\Scripts\activate
-
pip install openpyxl
pip install openpyxl
-
create start_idle.py
- Code Snippet
from idlelib.PyShell import main if __name__ == '__main__': main()
-
WINDOWS
notepad start_idle.py
- paste code snippet
- save and close
-
MAC
cat > start_idl.py <paste code snippet here> ^c
-
python start_idle.py
-
Copy the example code from openpyxl
-
In idle, File -> new file 'example.py'
-
Paste the example code
-
File -> Save
-
In the idle shell
import example
-
Quit idle. Close the example.py file
-
Open the 'sample.xlsx' file You should see data in the default worksheet generated by the example
- Census - Complete County File
- Consumer Complaints
- College Score Card
- Population by Country
- Create a new working directory.
- Create a new virtualenv. Don't forget to source the env!
- Pip install openpyxl.
- Download the 'Population by Country' as a local csv.
- Create a python file containing the csv to xlsx converter in this stackoverflow.
- Modify the code to convert the 'Population by Country'.
-
replace the line
f = open(r'C:\Users\Asus\Desktop\herp.csv')
-
with
f = open(r'C:\Users\Asus\Desktop\herp.csv', 'rU')
-
because of new-line character seen in unquoted field.
(mschober)-(jobs:0)-(~/Documents/git/classes/eca201/eca201/week1/homework) (! 1136)-> python csv_to_xlsx.py populationbycountry19802010millions.csv populationbycountry19802010millions.xlsx The source file is populationbycountry19802010millions.csv The target file is populationbycountry19802010millions.xlsx Begin converting to xlsx... Traceback (most recent call last): File "csv_to_xlsx.py", line 27, in <module> for row_index, row in enumerate(reader): _csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
-
- Convert the csv to xlsx and email to [email protected].
- subject: [eca201] - week1 homework
(env)
(mschober)-(jobs:0)-(~/Documents/git/classes/eca201/eca201/week1/homework)
(! 1137)-> vim csv_to_xlsx.py
(env)
(mschober)-(jobs:0)-(~/Documents/git/classes/eca201/eca201/week1/homework)
(! 1138)-> python csv_to_xlsx.py populationbycountry19802010millions.csv populationbycountry19802010millions.xlsx
The source file is populationbycountry19802010millions.csv
The target file is populationbycountry19802010millions.xlsx
Begin converting to xlsx...
Saving the converted file...
Success!
-
set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5" set "TK_LIBRARY=C:\Python27\tcl\tk8.5"
- set these as environment variables