第一个Python程序--Python

本文介绍了如何使用Sublime Text编辑器创建并运行你的第一个Python程序。通过编写打印'hello, world'的简单代码,你将在终端看到输出。如果你的系统中没有Python 3,可以使用Homebrew进行安装,并通过它安装Python和virtualenv。" 131467031,9639234,Matlab整数运算指南:加减乘除与取余,"['Matlab', '数值计算', '开发语言']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

写程序得先来个编辑器吧? Sublime Text ,提到编辑器就想到它了,很不巧我没用,你觉得顺手就行,反正就这么一提,Sublime Text

 

创建个.py后缀的文件:xxx.py;然后文件内写上第一行python代码,只需要一行就够了,按照国际惯例,因该是这样写的:

print('hello, world')

 

好啦,终端输入命令 python xxx.py         Duang ~~~~终端上输出了一行字符串hello, world   成功了

 

//这是机子上已经安装的各个版本Python的目录:进入这里查看/System/Library/Frameworks/Python.framework/Versions;

目前我的机子没有3.x版本的Python,需要安装一下;那么此时我想到神器homebrew了。

 

机子安装homebrew,用homebrew安装python,用pip安装virtualenv

brew search python3#查看python3是否存在
brew install python3#安装python3

命令行安装Python3的过程:

$ brew search python3

==> Formulae

boost-python3              python3                    python@3

$ brew install python3

Updating Homebrew...

==> Auto-updated Homebrew!

Updated 1 tap (homebrew/core).

==> New Formulae

buildkit        gitleaks        llvm@7          proper          s2geometry

ccls            go@1.11         mdbook          protobuf@3.6    solr@7.7

ffsend          kcov            operator-sdk    pyinstaller     triangle

==> Updated Formulae

openssl                   glibmm                     nqp

abcm2ps                    glm                        nspr

ack                        glog                       nss

acpica                     gloox                      ntp

activemq                   glui                       ocamlbuild

adwaita-icon-theme         gmic                       ocrmypdf

aide                       gmsh                       octave

allegro                    gmt                        odpi

amazon-ecs-cli             gmt@4                      opa

ammonite-repl              gnome-builder              opencoarrays

amqp-cpp                   gnome-latex                openfortivpn

angular-cli                gnupg                      openimageio

ansible                    gnuradio                   openrct2

anycable-go                gnutls                     openvdb

apache-arrow               go                         orc-tools

apache-arrow-glib          go-statik                  ori

apachetop                  gobject-introspection      osc

arangodb                   gocryptfs                  osm2pgsql

armadillo                  godep                      osquery

atk                        gomplate                   osrm-backend

atomist-cli                googler                    oxipng

aubio                      goreleaser                 pandoc

auditbeat                  gosu                       pandoc-citeproc

autossh                    gpgme                      parallel

aws-sdk-cpp                gr-osmosdr                 parallelstl

awscli                     gradle                     pcl

azure-cli                  grafana                    pdal

azure-storage-cpp          graph-tool                 pdftoedn

baobab                     grpc                       percona-server

bartycrouch                grv                        pgloader

bash                       gsettings-desktop-schemas  pgrouting

bazel                      gssh                       php

bedtools                   gtk+3                      php-code-sniffer

berkeley-db                gtkmm3                     php@7.1

bettercap                  gtksourceview3             php@7.2

binaryen                   gtksourceview4             phplint

bind                       gtranslator                phpunit

bit                        gucharmap                  picard-tools

bitcoin                    gwyddion                   pius

bitrise                    hadolint                   plantuml

bitwarden-cli              hapi-fhir-cli              platformio

bnd                        harfbuzz                   podofo

boost                      hebcal                     points2grid

boost-bcp                  helmfile                   polyml

boost-build                help2man                   ponyc

boost-mpi                  hg-fast-export             postgis

boost-python               highlight                  powerman

boost-python3              hledger                    ppsspp

bowtie2                    homeassistant-cli          presto

brew-gem                   homebank                   procyon-decompiler

btfs                       hub                        proj

bundletool                 i2pd                       prometheus

bzt                        imagemagick                protobuf

c-blosc                    immortal                   prototool

cabextract                 influxdb                   proxychains-ng

caddy                      instead                    pspg

caffe                      ipython                    ptex

cataclysm                  istioctl                   pulledpork

cdk                        jasper                     pulumi

ceres-solver               jenkins                    pumba

cfr-decompiler             jenkins-lts                pushpin

chakra                     jetty-runner               pygobject3

chapel                     jid                        pypy

checkbashisms              jpeg-turbo                 python

chezscheme                 json-fortran               qalculate-gtk

chronograf                 jsonrpc-glib               qt

cimg                       juju                       qxmpp

clamav                     julius                     r

cli53                      kafka                      rabbitmq

clojure                    kallisto                   rakudo

clojurescript              khal                       rakudo-star

cmake                      kibana                     rancher-cli

coffeescript               krakend                    rawtoaces

compcert                   ktmpl                      rbenv

conan                      kubecfg                    rbspy

conserver                  kubeprod                   re-flex

consul                     kubernetes-cli             rebar3

convox                     kubernetes-helm            redis

coreutils                  kustomize                  redis@3.2

coturn                     languagetool               redis@4.0

cppad                      lastpass-cli               rke

cpprestsdk                 ledger                     rst-lint

cromwell                   leptonica                  rtags

crowdin                    leveldb                    ruby

csvkit                     lf                         ruby-build

cucumber-cpp               lgogdownloader             ruby@2.5

curl                       libbitcoin                 s3fs

curl-openssl               libbitcoin-blockchain      s3ql

datamash                   libbitcoin-client          salt

dateutils                  libbitcoin-database        scalariform

dav1d                      libbitcoin-explorer        sceptre

dbhash                     libbitcoin-network         scrcpy

dep                        libbitcoin-node            scw

derby                      libbitcoin-protocol        sdl2

digdag                     libbitcoin-server          securefs

dlib                       libbluray                  serveit

dnscrypt-proxy             libdazzle                  serverless

dnsviz                     libdill                    servus

docfx                      libdvdread                 sfcgal

docker                     libetpan                   shadowsocks-libev

docker-completion          libfabric                  shapelib

docker-compose             libgaiagraphics            shellshare

doctl                      libgeotiff                 ship

doitlive                   libgosu                    shmux

double-conversion          libgpg-error               simple-scan

dovecot                    libgtop                    simple-tiles

dpkg                       libgweather                singular

dropbear                   liblcf                     sip

dssim                      liblwgeom                  skaffold

duply                      libosinfo                  slackcat

dynare                     libosmium                  solr

easyengine                 libphonenumber             source-highlight

easyrpg-player             libpointing                sourcery

efl                        libpulsar                  spatialite-gui

eiffelstudio               libqalculate               spatialite-tools

ejabberd                   librasterlite              speedtest-cli

elasticsearch              librdkafka                 sphinx-doc

embulk                     librealsense               spigot

emscripten                 libsoundio                 spirv-cross

epic5                      libsoup                    sqlcipher

erlang                     libspatialite              sqldiff

eslint                     libssh2                    sqlite

esptool                    libswiften                 sqlite-analyzer

etsh                       libtermkey                 stellar-core

exact-image                libtins                    step

exempi                     libtommath                 sundials

exim                       libtorrent-rasterbar       supersonic

exomizer                   libuv                      swagger-codegen@2

exploitdb                  libvirt                    swi-prolog

fades                      libyaml                    swiftformat

fastme                     libzip                     sxiv

fastqc                     lldpd                      taskell

fb-client                  llnode                     tbb

feh                        llvm                       telegraf

ffe                        logstash                   teleport

ffmpeg                     lolcat                     template-glib

fifechan                   lorem                      termtosvg

file-roller                lsd                        terraform

fio                        ltc-tools                  terraform-inventory

flatcc                     lynis                      terragrunt

flow                       mandoc                     thors-serializer

fltk                       mapnik                     tmux-xpanes

flume                      mapserver                  tokei

fluxctl                    mariadb                    tomcat

fn                         mas                        tomcat@7

folly                      maxwell                    tomcat@8

fontforge                  mdcat                      topgrade

fonttools                  menhir                     traefik

fortio                     mercurial                  treefrog

fossil                     mesa                       typescript

fping                      metaproxy                  ucloud

freedink                   metricbeat                 uhd

freeipmi                   mgba                       unbound

freeradius-server          micropython                upscaledb

freetds                    mingw-w64                  utf8proc

freetype                   minio                      v8

frugal                     minio-mc                   vala

fselect                    mint                       valabind

fstrm                      mitie                      vert.x

fuse-emulator              mkl-dnn                    vifm

fuse-zip                   mkvtoolnix                 vim

futhark                    mlkit                      vim@7.4

fwup                       mmark                      vte3

fx                         moarvm                     vtk

fzf                        monero                     vulkan-headers

gammu                      monit                      vultr

gdal                       mono                       watchexec

gearboy                    mpfr                       wesnoth

gearsystem                 mutt                       whois

gedit                      mvnvm                      widelands

geocode-glib               mvtools                    wildfly-as

geogram                    nano                       winetricks

geoserver                  nats-streaming-server      wolfssl

gerbil-scheme              nave                       wsk

getmail                    ncmpcpp                    wtf

gexiv2                     nco                        xapian

gif2png                    ncview                     xcodegen

gifski                     needle                     xpa

ginac                      neo4j                      xxhash

git-annex                  netcdf                     yarn

git-cola                   netdata                    yelp-tools

git-fixup                  netpbm                     ykpers

git-flow-avh               nghttp2                    you-get

gitbucket                  nginx                      youtube-dl

github-keygen              nicovideo-dl               yq

gitlab-runner              nifi                       zabbix

gjs                        nnn                        zenity

glib                       node                       zola

glib-networking            node-build                 zurl

==> Renamed Formulae

gloo-ctl -> glooctl

==> Deleted Formulae

at-spi2-atk     go@1.8          plan9port       solr@5.5        zxing-cpp

at-spi2-core    libutf          protobuf@2.5    solr@6.6

go@1.4          monax           protobuf@2.6    tmux-cssh

 

==> Installing dependencies for python: gdbm, openssl, readline, sqlite and xz

==> Installing python dependency: gdbm

==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1.mojave.bottle.1

######################################################################## 100.0%

==> Pouring gdbm-1.18.1.mojave.bottle.1.tar.gz

?  /usr/local/Cellar/gdbm/1.18.1: 20 files, 586.8KB

==> Installing python dependency: openssl

==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2r.mojave.bottl

######################################################################## 100.0%

==> Pouring openssl-1.0.2r.mojave.bottle.tar.gz

==> Caveats

A CA file has been bootstrapped using certificates from the SystemRoots

keychain. To add additional certificates (e.g. the certificates added in

the System keychain), place .pem files in

  /usr/local/etc/openssl/certs

 

and run

  /usr/local/opt/openssl/bin/c_rehash

 

openssl is keg-only, which means it was not symlinked into /usr/local,

because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

 

If you need to have openssl first in your PATH run:

  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

 

For compilers to find openssl you may need to set:

  export LDFLAGS="-L/usr/local/opt/openssl/lib"

  export CPPFLAGS="-I/usr/local/opt/openssl/include"

 

==> Summary

?  /usr/local/Cellar/openssl/1.0.2r: 1,795 files, 12.1MB

==> Installing python dependency: readline

==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.0.mojave.bottl

######################################################################## 100.0%

==> Pouring readline-8.0.0.mojave.bottle.tar.gz

==> Caveats

readline is keg-only, which means it was not symlinked into /usr/local,

because macOS provides the BSD libedit library, which shadows libreadline.

In order to prevent conflicts when programs look for libreadline we are

defaulting this GNU Readline installation to keg-only.

 

For compilers to find readline you may need to set:

  export LDFLAGS="-L/usr/local/opt/readline/lib"

  export CPPFLAGS="-I/usr/local/opt/readline/include"

 

==> Summary

?  /usr/local/Cellar/readline/8.0.0: 48 files, 1.5MB

==> Installing python dependency: sqlite

==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.27.2.mojave.bottle

######################################################################## 100.0%

==> Pouring sqlite-3.27.2.mojave.bottle.tar.gz

==> Caveats

sqlite is keg-only, which means it was not symlinked into /usr/local,

because macOS provides an older sqlite3.

 

If you need to have sqlite first in your PATH run:

  echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

 

For compilers to find sqlite you may need to set:

  export LDFLAGS="-L/usr/local/opt/sqlite/lib"

  export CPPFLAGS="-I/usr/local/opt/sqlite/include"

 

==> Summary

?  /usr/local/Cellar/sqlite/3.27.2: 11 files, 3.7MB

==> Installing python dependency: xz

==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.4.mojave.bottle.tar.

######################################################################## 100.0%

==> Pouring xz-5.2.4.mojave.bottle.tar.gz

?  /usr/local/Cellar/xz/5.2.4: 92 files, 1MB

==> Installing python

==> Downloading https://homebrew.bintray.com/bottles/python-3.7.3.mojave.bottle.

######################################################################## 100.0%

==> Pouring python-3.7.3.mojave.bottle.tar.gz

==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install

==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install

==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install

==> Caveats

Python has been installed as

  /usr/local/bin/python3

 

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to

`python3`, `python3-config`, `pip3` etc., respectively, have been installed into

  /usr/local/opt/python/libexec/bin

 

If you need Homebrew's Python 2.7 run

  brew install python@2

 

You can install Python packages with

  pip3 install <package>

They will install into the site-package directory

  /usr/local/lib/python3.7/site-packages

 

See: https://docs.brew.sh/Homebrew-and-Python

==> Summary

?  /usr/local/Cellar/python/3.7.3: 3,863 files, 59.8MB

==> Caveats

==> openssl

A CA file has been bootstrapped using certificates from the SystemRoots

keychain. To add additional certificates (e.g. the certificates added in

the System keychain), place .pem files in

  /usr/local/etc/openssl/certs

 

and run

  /usr/local/opt/openssl/bin/c_rehash

 

openssl is keg-only, which means it was not symlinked into /usr/local,

because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

 

If you need to have openssl first in your PATH run:

  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

 

For compilers to find openssl you may need to set:

  export LDFLAGS="-L/usr/local/opt/openssl/lib"

  export CPPFLAGS="-I/usr/local/opt/openssl/include"

 

==> readline

readline is keg-only, which means it was not symlinked into /usr/local,

because macOS provides the BSD libedit library, which shadows libreadline.

In order to prevent conflicts when programs look for libreadline we are

defaulting this GNU Readline installation to keg-only.

 

For compilers to find readline you may need to set:

  export LDFLAGS="-L/usr/local/opt/readline/lib"

  export CPPFLAGS="-I/usr/local/opt/readline/include"

 

==> sqlite

sqlite is keg-only, which means it was not symlinked into /usr/local,

because macOS provides an older sqlite3.

 

If you need to have sqlite first in your PATH run:

  echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

 

For compilers to find sqlite you may need to set:

  export LDFLAGS="-L/usr/local/opt/sqlite/lib"

  export CPPFLAGS="-I/usr/local/opt/sqlite/include"

 

==> python

Python has been installed as

  /usr/local/bin/python3

 

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to

`python3`, `python3-config`, `pip3` etc., respectively, have been installed into

  /usr/local/opt/python/libexec/bin

 

If you need Homebrew's Python 2.7 run

  brew install python@2

 

You can install Python packages with

  pip3 install <package>

They will install into the site-package directory

  /usr/local/lib/python3.7/site-packages

 

See: https://docs.brew.sh/Homebrew-and-Python

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值