/*auto readmore*/ /*auto readmore*/ /* an hien script*/ // an hien password /*an hien ma chuong trinh cong tru */ /*Scrollbox thanh cuon*/ /***Nhung CODE***/ /* dòng xanh dòng trắng */ /* https://cdnjs.com/libraries/prism lay thu vien, can vao ten file ma goi 1. copy link vao vi du:prism-python.min.js 2. ten ngon nua la python */ /*=== New posts ===*/ /*header slider*/ /*=== bai viet lien quan===*/ /*===tabcode===*/

Python, Cài Đặt Python Trên Windows

Yêu cầu:
1. Download và Cài đặt
2. Thiết lập path cho Python
3. Thực hiện phép tính đơn giản
4. Cài đặt PIP trên windows
5. Cài thư viện thông qua PIP
6. Cài ipython trên windows

Thực hiện:

1. Download và Cài đặt

Chọn phiên bản cần download


Làm theo các bước như hình

2. Thiết lập path cho Python

Vào Command Prompt gõ python ta thấy hiển thị thông báo lỗi, nên chúng ta phải thiết lập path trên máy tính để khắc phục lỗi này.

Làm theo các bước như hình, phần Path của System Variable ta thêm vào đường dẫn trỏ đến thư mục đã cài đặt Python trước đó, trong ví dụ này là "C:\Program Files (x86)\Python38-32"

Thiết lập path trên Windows 10:


Khởi động lại máy tính và kiểm tra

Python đã hoạt động ở Windows Command Prompt

3. Thực hiện phép tính đơn giản


Ta thấy khi gõ phép tính và enter sẽ cho ra kết quả liền sau đó. Trong trường hợp người ta gọi là chương trình PHIÊN dịch (nó sẽ thực hiện sau mỗi dòng khi ta gõ enter), còn chương trình BIÊN dịch là khi ta viết xong một đoạn code hay một hàm,... nhấn chạy lúc đó nó mới thực hiện.

4. Cài đặt PIP trên windows

Noted: Với cài đặt trên đã được cài đặt rồi. Mục này chúng tôi hướng dẫn với trường hợp của cài PIP




  • Cài đặt PIP
Chạy cmd Run as administrator -> chuyển đến thưc mục lưu file get_pip.py vừa download (trong lab này là C:\Users\Admin\Downloads>) -> gõ python get_pip.py

  • Chỉnh path cho PIP
Trong bài lab này là "C:\Program Files (x86)\Python38-32\Scripts"


  • Kiểm tra version PIP bằng lệnh pip --version

C:\Users\Admin\Downloads>pip --version
pip 20.1.1 from c:\program files (x86)\python38-32\lib\site-packages\pip (python 3.8)
C:\Users\Admin\Downloads>

Version hiện tại là 20.1.1, tuy nhiên chúng ta có thể downgrade xuống version 18.1 (thấp hơn) hoặc upgrade lên version mới hơn

downgrade
python -m pip install pip==18.1

upgrade
python -m pip install --upgrade pip

5. Cài thư viện thông qua PIP
  • Kiểm tra trước khi cài đặt

C:\Users\Admin\Downloads>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import netmiko
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'netmiko'
>>>

Ví dụ trên chúng tôi muốn dùng thư viện netmiko, thông báo lỗi là không tìm thấy thư viện netmiko
C:\Users\Admin\Downloads>pip install netmiko
Collecting netmiko
  Using cached netmiko-3.1.1-py2.py3-none-any.whl (147 kB)
Collecting pyserial
  Using cached pyserial-3.4-py2.py3-none-any.whl (193 kB)
Collecting scp>=0.13.2
  Using cached scp-0.13.2-py2.py3-none-any.whl (9.5 kB)
Collecting paramiko>=2.4.3
  Using cached paramiko-2.7.1-py2.py3-none-any.whl (206 kB)
Requirement already satisfied: setuptools>=38.4.0 in c:\program files (x86)\python38-32\lib\site-packages (from netmiko) (41.2.0)
Collecting textfsm
  Using cached textfsm-1.1.0-py2.py3-none-any.whl (37 kB)
Collecting bcrypt>=3.1.3
  Using cached bcrypt-3.1.7-cp38-cp38-win32.whl (26 kB)
Collecting cryptography>=2.5
  Using cached cryptography-2.9.2-cp38-cp38-win32.whl (1.3 MB)
Collecting pynacl>=1.0.1
  Using cached PyNaCl-1.4.0-cp38-cp38-win32.whl (193 kB)
Collecting six
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Processing c:\users\admin\appdata\local\pip\cache\wheels\8e\70\28\3d6ccd6e315f65f245da085482a2e1c7d14b90b30f239e2cf4\future-0.18.2-py3-none-any.whl
Collecting cffi>=1.1
  Using cached cffi-1.14.0-cp38-cp38-win32.whl (165 kB)
Collecting pycparser
  Using cached pycparser-2.20-py2.py3-none-any.whl (112 kB)
Installing collected packages: pyserial, pycparser, cffi, six, bcrypt, cryptography, pynacl, paramiko, scp, future, textfsm, netmiko
Successfully installed bcrypt-3.1.7 cffi-1.14.0 cryptography-2.9.2 future-0.18.2 netmiko-3.1.1 paramiko-2.7.1 pycparser-2.20 pynacl-1.4.0 pyserial-3.4 scp-0.13.2 six-1.15.0 textfsm-1.1.0
C:\Users\Admin\Downloads>

  • Kiểm tra sau khi cài thư viện netmiko
C:\Users\Admin\Downloads>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import netmiko
>>> netmiko.__version__
>>>'3.1.1'
>>>
>>>

Chúng ta thấy không còn báo lỗi nữa, và phiên bản hiện tại là 3.1.1.


6. Cài ipython trên windows


C:\Users\Administrator>pip install ipython
Collecting ipython
  Downloading https://files.pythonhosted.org/packages/aa/e8/47fda10c3ab103d9d4a667b40da9afd542c4e50aeb00c861b4eee5bb4e8f/ipython-7.1 none-any.whl (783kB)
     |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 788kB 1.1MB/s
Collecting colorama; sys_platform == "win32" (from ipython)
  Downloading https://files.pythonhosted.org/packages/c9/dc/45cdef1b4d119eb96316b3117e6d5708a08029992b2fee2c143c7a0a5cc5/colorama-0.py3-none-any.whl
Collecting pygments (from ipython)
  Downloading https://files.pythonhosted.org/packages/2d/68/106af3ae51daf807e9cdcba6a90e518954eb8b70341cee52995540a53ead/Pygments-2.none-any.whl (914kB)
     |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 921kB 6.4MB/s
Collecting jedi>=0.10 (from ipython)
  Downloading https://files.pythonhosted.org/packages/07/83/7e711550fcb2722f1ca9c8564d5bb23f625ae67d99f4a360b428c0f3e932/jedi-0.17.1-none-any.whl (1.4MB)
     |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.4MB 6.4MB/s
Collecting decorator (from ipython)
  Downloading https://files.pythonhosted.org/packages/ed/1b/72a1821152d07cf1d8b6fce298aeb06a7eb90f4d6d41acec9861e7cc6df0/decorator-4.py3-none-any.whl
Collecting prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 (from ipython)
  Downloading https://files.pythonhosted.org/packages/e4/a7/81b39aa50e9284fe2cb21cc7fb7de7817b224172d42793fd57451d38842b/prompt_tool5-py3-none-any.whl (351kB)
     |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 358kB 6.4MB/s
Requirement already satisfied: setuptools>=18.5 in c:\program files (x86)\python38-32\lib\site-packages (from ipython) (41.2.0)Collecting backcall (from ipython)
  Downloading https://files.pythonhosted.org/packages/4c/1c/ff6546b6c12603d8dd1070aa3c3d273ad4c07f5771689a7b69a550e8c951/backcall-0.py3-none-any.whlCollecting traitlets>=4.2 (from ipython)
  Downloading https://files.pythonhosted.org/packages/ca/ab/872a23e29cec3cf2594af7e857f18b687ad21039c1f9b922fac5b9b142d5/traitlets-4.py3-none-any.whl (75kB)
     |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 81kB 2.6MB/s
Collecting pickleshare (from ipython)
  Downloading https://files.pythonhosted.org/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/picklesharey2.py3-none-any.whl
Collecting parso<0.8.0,>=0.7.0 (from jedi>=0.10->ipython)
  Downloading https://files.pythonhosted.org/packages/b5/61/998cce9e7476de000d031874df26a18f67cb73448164fc44a98f0c55920b/parso-0.7.0-none-any.whl (100kB)
     |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 102kB 6.4MB/s
Collecting wcwidth (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython)
  Downloading https://files.pythonhosted.org/packages/59/7c/e39aca596badaf1b78e8f547c807b04dae603a433d3e7a7e04d67f2ef3e5/wcwidth-0.2y3-none-any.whl
Collecting six (from traitlets>=4.2->ipython)
  Downloading https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-none-any.whl
Collecting ipython-genutils (from traitlets>=4.2->ipython)
  Downloading https://files.pythonhosted.org/packages/fa/bc/9bd3b5c2b4774d5f33b2d544f1460be9df7df2fe42f352135381c347c69a/ipython_gen2.0-py2.py3-none-any.whl
Installing collected packages: colorama, pygments, parso, jedi, decorator, wcwidth, prompt-toolkit, backcall, six, ipython-genutils,ts, pickleshare, ipython
Successfully installed backcall-0.2.0 colorama-0.4.3 decorator-4.4.2 ipython-7.15.0 ipython-genutils-0.2.0 jedi-0.17.1 parso-0.7.0 pre-0.7.5 prompt-toolkit-3.0.5 pygments-2.6.1 six-1.15.0 traitlets-4.3.3 wcwidth-0.2.5
C:\Users\Administrator>

Ví dụ kiểm tra ipython đã cài đặt thành công

Xong!
P/s: netmiko là thư viện gì, tại sao thử với thư viện này, hẹn các bạn ở các bài lab sau


No comments:

Post a Comment

/*header slide*/