Cara menggunakan im save python
01 Oct 2020 đ python tutorials vscode windows salesforce
beginner Show
My beloved Spyder IDE suddenly stopped working on me, and I needed to install Python + Pandas on a new computer anyway, so I decided to explore installing Python (and various packages I use with it such as Pandas) out of the Windows Store, executing code in VSCode as an IDE. The Windows installation of Python is pretty stripped down, like that of Miniconda, and similarly doesnât require admin rights to oneâs computer. Therefore, Iâll cover hand-installing a few simple packages as in my older tutorial. Note: This tutorial is aimed at non-programmers who just want to edit a few CSV files with Python. If youâre a serious data scientist, learn the nuts and bolts of Anaconda at Real Pythonâs âSetting Up Python for Machine Learning on Windowsâ Did you get Python up and running? Yay! Iâm thrilled I could help. If youâd like, Iâd love a Ko-Fi. (Chai for me!) đ„° Installing Windows-Store Python & running a Python programInstall Python from the Windows storeClick the Windows icon in the bottom-left corner of your screen, and then without clicking anything else, type the word
â The Windows start menu should filter your list of available programs to suggest the Microsoft Store app. Click it. In the upper right corner of the store window, click the text entry panel next to a magnifying glass and type the word â Available software to download should filter itself. Click the piece of Software named âPython #.#â but not âPython #.# (RC)â where â#.#â is some number. I suggest choosing the greatest non-RC number available to you (3.8 at the time of writing this tutorial, although as you can see in the screenshot, 3.7 is also available to me). Verify the legitimacy of the software by checking that the Python Software Foundation is the publisher of the software, then click the big blue âGetâ button. The button will be replaced by a meter indicating your download and installation progress. When finished, you can close the Store app. Click the Windows icon in the bottom-left corner of your screen â at the top of your start menu, you should see âPython #.#â and âIDLE (Python #.#)â software added. (Alternatively, they should be under âPâ and âI,â respectively, in your start menuâs main list of programs.) If youâd like, you can click one of them and try running Some tech details for nerdsSkip this little list if it doesnât make any sense to you
Hello World: running a Python programOpen up a nice text editor like Notepad++. Create a new file. In it, type the following text, using the apostrophe key on your keyboard for the single quotes: Do âFile -> Save As.â Pick a nice folder for your program (personally, Iâm going to save mine under Once youâve done that, open a âcommand-line promptâ by hitting the Windows key on your keyboard, typing â At the prompt, type something along the following lines, only changing the file paths to be where your
â
You should see â IDEsSetting up an IDE for pleasant programmingThat wasnât a particularly fun way to code, was it? If youâve practiced coding in an online âIDEâ like Repl.it or CodeBunk, you know that coding can be as easy as clicking a big ârunâ button every time you type enough text that you wonder what it does. To get the same experience, we need to install an âIDEâ on our PC. A popular one is Microsoftâs VSCode. Install VSCodeInstalling VSCode is a straightforward process of downloading the software from Microsoftâs web site and double-clicking the installer file, then following directions as prompted. I donât have screenshots because it was already installed on my computer. I have admin rights to the computer I was working on, so please let me know in the comments if this tutorial doesnât work for you in a pure no-admin-rights context â I suspect I installed VSCode for the whole computer when I installed it. Microsoft has some tips on installing VSCode for a local user, without admin rights, here. Once youâve installed VSCode, run it. Python-ifying VSCode with a pluginAt the far left of VSCode, click the bottom icon that looks like a square joining 3 other squares to make a bigger square. This will bring you to the Extensions section of VSCode. In the search box at the top of the left-hand control for Extensions, type â Click the green Install button. When your extension finishes installing, it might let you know that thereâs a way to change which Python interpreter VSCode uses to facilitate executing code written in the Python programming language. Go ahead and click âGot it!â if so. Just for fun, click â VSCodeâs command pallet will open toward the top center of VSCode and give you an option to choose which (Programmers sometimes keep multiple versions of Python installed on their computer all at once.) Click anywhere outside this command pallet menu to get rid of it. I just wanted to show you around in case you were curious. Using our IDE to programClose VSCode and fire it up again. You might not see Thatâs okay â you can bring it back by navigating through the top menu to File > Open File and opening the file you saved at, for example, (Note: I closed out of the tip that popped up telling me I hadnât yet installed a âlinter.â) You should see that To run this code, click the green right-facing triangle (the âplay buttonâ / ârun buttonâ) toward the top right corner of VSCode. If it gives you a drop-down menu, choose âRun Python File in Terminal.â In the âTerminalâ tab of a panel below your code, you should see the words: It should appear between âcommand promptsâ that say:
Now erase the entire contents of the file, and on line 1, type: Then click the big green ârunâ button. In the âTerminalâ output below, do you see the following output text? Congratulations â youâve set up VSCode and youâre almost ready to write bigger programs! In the top menu, click âFileâ -> âSaveâ because why not be proud of this working code? Itâs good to get used to saving your work as soon as you like it. Some tech details for nerds
VSCode should have filled in the command prompt before âHello Worldâ with something along the lines of The command prompt after âHello Worldâ should be available for you to type commands into. Try typing â Youâll be using the Terminalâs command prompt when you need to update extensions to Python, so you might as well try your first command in it. ModulesChecking whether âmodulesâ are installedNow you need to learn what it looks like when a given extension to the Python language, also known as a âlibraryâ or âpackageâ or, particularly in Python, a âmodule,â is installed. Backspace out the entirety of your code and on line 1, type: Click the ârunâ button. If you get a dump of text in your console, saying the
following, you now know that you donât have the module called â
If you do have âpandasâ installed, nothing special happens. If you have âpandasâ installed, when you run this code, you just get a new command prompt (â Letâs fix things and install Pandas so our code runs. Installing a âmoduleâWhen using the Windows Store installation of Python, youâll use the âpip installerâ to install extended Python commands (âmodulesâ) onto your computer so that you can run Python code written with these extended commands. PIP is just a command-line program that works in the command prompts of the Terminal pane of VSCode. It goes out and downloads things from the internet and installs them on your computer for you. In the command prompt in your Terminal pane in VSCode, type the following and hit âenterâ to execute: You may notice that PIP downloaded a lot more than just âpandas.â Thereâs another package thatâs highly intertwined with âpandasâ called ânumpyâ that itâs going to download for us ⊠weâll check after weâre all done that it installed, too. The download and install takes a few minutes. The installation process is completete when you see a new
command prompt (â Run your code again, which, as a reminder, looks like this: Now you should get the boring ânothing happens except the command prompt incrementingâ thing. Note: If youâd like to see that the ânumpyâ module also installed, add a 2nd line of code to your program at left and click âRunâ again, with the full code being:
Installing another moduleThe same process works for other Python modules, like Simple Salesforce, which makes it easier to download and update data in a Salesforce database. Running the following code will produce an error if Simple Salesforce is not installed, but will do nothing if it is installed: To install Simple Salesforce on your computer, just run this command in the VSCode Terminal command prompt:
Note: in pip commands, this module is âsimple-salesforceâ with a hyphen. When doing an âimportâ in Python code, itâs an underscore. Not sure why ⊠thatâs just how the author packaged it up. Updating a âmoduleâHas it been a year, and youâve heard there are newer & greater versions of Pandas? At your prompt in the VSCode Terminal, run the following command:
Updating Python itselfIf you have, say, version 3.8.0 and you want to bring your system up to the latest version offered in the Microsoft Store (for me today, thatâs 3.8.6), you might be able to do so as described in âHow to manually update apps and games from the Microsoft Storeâ by Ciprian Adrian Rusen for Digital Citizen. If, on the other hand, you chose version 3.7 of Python and want to switch to version 3.8, I think the easiest way to ensure you keep your installation simple would be to simply uninstall Python the way youâd install any program from Windows, then reinstall it. The only catch is that this will likely uninstall all the modules youâve installed with pip. Maybe you want a clean start, but for this tutorial, weâll take a backup of the list of those modules before we begin and reinstall them when done.
After updating Python, you might also want to update all of your modules at once to their latest versions. You can do so with the following command suggested in this blog post by ActiveState: Updating all modules at once
Updating PIPFunnily, pip itself doesnât get upgraded when you âupdate everything,â so if youâre seeing nastygrams that itâs out-of-date, you can also run:
Happy ProgrammingYou now have a working environment for editing CSV files in Python!
Door PrizeHereâs a âdoor prize scriptâ to get you started: try copying & pasting it into
You should see the following output in your console at right:
Now youâve opened a CSV spreadsheet file with Python â youâre off to the races! Head here to learn new skills and put them in action on your computer. |