0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonさんこんにちは。

Last updated at Posted at 2017-08-26

python3を使いたくなったので最初のところのメモ。

python3を入れる


localhost:~ yoichan$ python3
-bash: python3: command not found
localhost:~ yoichan$ brew install python3

...

localhost:~ yoichan$ python3 -V
Python 3.6.2

virtualenvを入れる


localhost:~ yoichan$ pip3 install virtualenv
Collecting virtualenv
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 397kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
localhost:work yoichan$ virtualenv Komachin
Using base prefix '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/yoichan/work/Komachin/bin/python3.6
Also creating executable in /Users/yoichan/work/Komachin/bin/python
Installing setuptools, pip, wheel...done.

環境を作る


localhost:work yoichan$ mkdir Komachin
localhost:work yoichan$ cd Komachin/
localhost:Komachin yoichan$ mkdir env
localhost:Komachin yoichan$ virtualenv env
Using base prefix '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/yoichan/work/Komachin/env/bin/python3.6
Also creating executable in /Users/yoichan/work/Komachin/env/bin/python
Installing setuptools, pip, wheel...done.

activateするとつくった環境のコマンドが使われる


localhost:Komachin yoichan$ source env/bin/activate
(env) localhost:Komachin yoichan$ which python
/Users/yoichan/work/Komachin/env/bin/python
(env) localhost:Komachin yoichan$ which pip
/Users/yoichan/work/Komachin/env/bin/pip
(env) localhost:Komachin yoichan$ ls -l env/bin/
total 136
-rw-r--r--  1 yoichan  staff   2089  8 26 17:46 activate
-rw-r--r--  1 yoichan  staff   1031  8 26 17:46 activate.csh
-rw-r--r--  1 yoichan  staff   2185  8 26 17:46 activate.fish
-rw-r--r--  1 yoichan  staff   1137  8 26 17:46 activate_this.py
-rwxr-xr-x  1 yoichan  staff    262  8 26 17:46 easy_install
-rwxr-xr-x  1 yoichan  staff    262  8 26 17:46 easy_install-3.6
-rwxr-xr-x  1 yoichan  staff    234  8 26 17:46 pip
-rwxr-xr-x  1 yoichan  staff    234  8 26 17:46 pip3
-rwxr-xr-x  1 yoichan  staff    234  8 26 17:46 pip3.6
lrwxr-xr-x  1 yoichan  staff      9  8 26 17:46 python -> python3.6
-rwxr-xr-x  1 yoichan  staff   2348  8 26 17:46 python-config
lrwxr-xr-x  1 yoichan  staff      9  8 26 17:46 python3 -> python3.6
-rwxr-xr-x  1 yoichan  staff  13068  8 26 17:46 python3.6
-rwxr-xr-x  1 yoichan  staff    241  8 26 17:46 wheel

hello worldしてみる


(env) localhost:scripts yoichan$ vi hello.py

# hello.py
print("Hello world!")

(env) localhost:scripts yoichan$ python hello.py
Hello world!

よさそう。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?