pycharm快速开始英文版.docx
《pycharm快速开始英文版.docx》由会员分享,可在线阅读,更多相关《pycharm快速开始英文版.docx(23页珍藏版)》请在冰豆网上搜索。
pycharm快速开始英文版
QuickStartGuide.ExploringtheIDE
WelcometoPyCharm!
ThisshortguideaimstohelpyougetagriponthePyCharmIDE.
Beforeyoustart…
∙Makesurethatatleastone Python interpreter,versionfrom2.4to3.4isproperlyinstalledonyourcomputer.
∙MindthatPyCharmisavailableintwoeditions:
CommunityandProfessional.Thedifferencebetweentheeditionsisexploredin EditionComparisonMatrix.
Notethatthe downloadpage containsinstallationinstructionsforthevariousplatforms;theseinstructionsmayvaryforthedifferentoperatingsystems.
Initialsetup
IfthisistheveryfirsttimeyoulaunchyourPyCharm,itwillaskyouseveralimportantquestions:
∙First,whetheryoualreadyhavesettingyouwanttopreserve(forexample,fromapreviousversion)
∙Yourlicenseinformation
∙And,finally,whichkeymapandthemeyouwanttouse:
NotethatPyCharmhasseveralpre-definedkeymaps:
forthosewholikeEclipseorVisualStudio,fortheEmacsfans,GNOME,KDEandmore.Explorethelistofavailablekeymapsinthe Keymappage ofSettings/Preferencesdialog.
ForthededicatedVimusers,PyCharmsuggests IdeaVimplugin thathelpscodinginPyCharmasifintheVimeditor.ForthosewhocannotlivewithoutrealEmacs,PyCharmprovidesthepossibilityto useitasanexternaleditor.
Iflateryoudecidethatyourinitialchoicewaswrong,youcanalwayschangeyoursettings.TolearnmoreaboutconfiguringtheIDEthemeandkeymap,refertoour documentation andtutorials:
Seealso:
GettingstartedwithPyCharmConfiguringkeyboardschemes
SettingdefaultsfromtheWelcomescreen
Again,ifthisisyourveryfirststart(orifyouhavenoopenproject),you'llseethe Welcomescreen.IfyouclickthelinkConfigure,you'llseethepageoftheWelcomescreenthatsuggestsyoutoconfigureyourenvironment,plugins,importandexportsettings.YouhavetoclickConfigureoncemore-andseethe Settings/Preferencesdialog.Ifyoulookatthisdialog,you?
llnoticetheheader"DefaultProject":
Whatdoesitmean?
Thesesettingswillbeusedeverytimeyoucreateanewproject.Forexample,youwantallyounewlycreatedprojectstousethesameinterpreter-OK,youcan definesuchaninterpreter intheTemplateProjectSettings.
TheIDEsettingscharacterizeyourworkingenvironment(keymaps,colorschemesetc.)Forexample,youwantyoureditortoalwaysshowlinenumbers.IntheSettings/Preferencesdialog,gototheIDEsettings,expandthenodeEditor,andinthe Appearancepage,selectthecheckbox"Showlinenumbers":
Next,supposeyouwanttousesomeparticularcolorschemefortheeditor,andyouarenothappywiththecolorssuggestedbydefault.OK,selectthebasescheme,createitscopy,andthenchangecolors(theschemessuggestedbydefaultarenoteditable).
Itisalsopossibletosetyourpreferredfontsizefortheeditor-thisisdoneintheFontspageoftheColorsandFontssettings.Again,youhavetocreateacopyoftheschemefirst,ifyouhaven'tdoneitalready,andthenspecifythedesiredfontsizefortheeditor.Thisfontsizewillapplytothecurrenteditortabs,andallthenewlyopenededitors.However,itdoesnotaffectthefontsizeoftheIDEcomponents.
NotethatyoucanalwaysseetheresultsofyourexperimentsinthePreviewpane:
Thewholeprocedureisdescribedstep-by-stepinthetutorial WhatmyPyCharmlookslike.
Whenaprojectisalreadycreated,youcanchangeitssettingsatanymoment.Configuringsettingsforthecurrentprojectwillbediscussedalittlebitlater,inthesection Customizeeverythingforyourproject!
.
Finally,youcanshoworhideactuallyalltheUIelements:
toolbarbuttons,mainmenu,maintoolbar(menuView);PyCharmalsoenablesyoutochooseviewingmode.Refertothedocumentationfordetails:
Seealso:
PyCharmtoolwindowsPresentationandFullScreenviewingmodes
Project
EverythingyoudoinPyCharm,isdonewithinthecontextofa project.WhatismostinterestingaboutPyCharmprojectmanagement,isthepossibilityto openmultipleprojectsinoneframe.Whenyoucreateanewproject(File→NewProject),oropenanexistingone(File→Open),PyCharmsuggestsyoutochoosewhichwayyouwanttheprojecttobeopened:
inanewwindow,inthesamewindowafterclosingthepreviouslyopenedproject,oraddedtothepreviouslyopenedproject.
Youcanhaveasmanyprojectsopenedinonewindowasrequired.Sodoing,thefirstprojectisconsideredtheprimaryproject.Allthesymbolsoftheaddedprojectsarevisiblefromtheprimaryproject.
Asanexercise,createanewemptyproject,whereyoucandevelopsomepurePythoncode.Thiscaseisdiscussedindetailinthetutorial GettingstartedwithPyCharm —inparticular,thesectionCreatingasimpleproject.
Typesofprojects
Bytheway,PyCharmsuggestscreatingprojectsofthevarioustypes:
Django,Flask,Pyramid,web2py,etc.Youcanexploretheavailabletypesyourself,whencreatinganewproject-justselectthenewprojecttypefromthedrop-downlist:
Asyousee,PyCharmsupportsallthemajorPython-basedframeworks.Foreachofthesupportedprojecttypes,PyCharmcreatesthecorrespondingfileanddirectorystructure,andallthenecessaryartifacts.Refertotheproductdocumentation:
∙Django
∙Flask
∙Pyramid
∙GoogleAppEngine
∙Web2Py
Starter
OK,yourprojectisready.Beforeyoustartworkingwithit,justpress Shift twice.You'llseeapop-upwindowthatallowsfindinganythingandjumpingeverywhere:
Asyousee,thiswayonecansearchamongtheactions,settings,files,IDEcomponents,andmore.Notethatitisjustoneofthenumerousnavigationfeatures.We'llreturntothePyCharm'ssearchandnavigationfacilities alittlebitlater.
Customizeeverythingforyourproject!
Lookatthemaintoolbar—thereistheSettingsbutton
.ClickingthisbuttonopenstheSettings/Preferencesdialogbox,whereyoucanchangeyourprojectstructure,setupversioncontrol,andtweakyourworkingenvironmenttomakethedevelopmentprocessarealpleasure.
Someofthesettingspertaintoaparticularproject—forexample,projectinterpreter,versioncontrolconfiguration,orfilecolors.Theothers—liketheEditorsettings,keymaps,orlivetemplates—pertaintoyourwholeworkingenvironment,andthuscanbeconfiguredevenwithoutanopenproject.
Projectinterpreter
Pythoninterpreterisvital—withoutityouwillnotbeabletodoanything...PyCharmwillwarnyou,ifyoumanagetocreateaprojectwithoutaninterpreter:
InPyCharm,youcandefineseveralPythoninterpreters-theyjustcomprisethelistofinterpreters,availableonyourmachine.Fromamongthem,youcanchoosetheonetobeusedinyourproject.
YouneedtotellPyCharmwhichPythoninterpreteryouwanttousesinceitcan useadifferentinterpreterforeachproject:
PyCharmwillusethisinformationforindexing.
YoucanusePythoninterpretersofthefollowingtypes:
∙Local
∙Remote
∙Virtualenvironments
Localinterpreter
Thisisthemoststraightforwardwayofusinganinterpreter.YoudownloadaPythoninterpreter,installitonyourmachine,andthenspecifythePythonexecutable...Refertothe tutorial or productdocumentation.
Remoteinterpreter
WithPyCharm,youcanuseinterpreterslocatedremotely,forexample,onareliableserver.Sodoing,PyCharmmakesitpossibletoconfigureremoteinterpretersvia SSHconnection,orvia Vagrantbox.
Refertothetutorial ConfiguringinterpreterswithPyCharm.
Virtualenvironment
Whydoweneeditall?
Suppose,youareworkingononeprojectthatmakesuseof,say,Django1.6,andatthesametimesupportanotherprojectrequiringDjango1.2.Insuchacase,youneedsomethingthatkeepsyourenvironmentsafeandconsistent-atoolthatallowscreatinganisolatedworkingcopyofaPythoninterpreter.Learnhowtocreateavirtualenvironmentinthedocumentation and tutorial.
Packagesandpaths
Regardlessoftheinterpretertype,PyCharmhelpsinstallandupdatethenecessarypackagesandpaths.Forexample,whenPyCharmautomaticallydetectsthatsomeoftherequiredpackagesaremissingoroutdated,itsuggestsyoutoinstallorupgradethem:
Samethinghappenswiththepaths.Ifyouhaveinstalledorupgradedlibraries,itisagoodideatorescanthePythoninstallation.Clickthegearbutton
locatedtotherightoftheprojectinterpreterfield,andchoose More.Then,intheProjectInterpretersdialog,selecttheinterpreteryouwanttoviewthepathsfor,click
andthen,intheInterpreterPathsdialog,refreshpackages
:
Finddetailsinthe productdocumentation.
VCS
Surely,youkeepyoursourcesunderaversioncontrol,right?
Git?
SVN?
Mercurial?
WithPyCharm,it'seasytosetup,andagaintheIDEdoesagoodjobauto-detectingtheVCSalreadyusedforexistingprojects.
Butyoucanfine-tune—justclick VersionControl nodeinthe Settings/Preferencesdialog (ProjectSettings→VersionControl).Bydefault,youwillseeprojectrootdirectoryonly,butyoucanbreakyourapplicationdownintosmallerchunks,andplacevirtuallyeverydirectoryunderitsownversioncontrolsystem.
Inthe Settings/Preferencesdialog,youcanalsodefinesomebehaviorsthatarecommontoallversioncontrolsystems:
confirmationoncreatingordeletingfiles,tasksperformedinthebackground,ignoringunversionedfilesandmore.
Refertothetutorials:
∙Versioncontrolbasics
∙UsingPyCharm'sGitintegrationlocally
∙Sharingviaaremoterepository
Seealso:
VersioncontrolwithPyCharmVersioncontrolprocedures
Filecolors
Yourprojectmightcontainseveralsites,eachonewithitsownsetoffileswiththesamenames(init.py,models.py,tests.py,views.py).Whentheyareopenedintheeditor,it'sra