Ở bài trước chúng ta đã biết sơ qua về Python, ưu điểm và những lĩnh vực có thể sử dụng ngôn ngữ lập trình này. Để bắt đầu làm quen với Python, trước tiên bạn cần cài đặt Python trên máy tính đang dùng, có thể là Windows, macOS hoặc Linux.

Dưới đây là hướng dẫn cài đặt Python trên máy tính, cụ thể cho từng hệ điều hành.

Cài đặt và chạy Python trên Windows

Tải Python tại đây: https://www.python.org/downloads/, chọn phiên bản bạn cần, trong bài viết này chúng tôi chọn Python 3.6.

Nhấp đúp vào file vừa tải về để cài đặt. Tại đây có 2 tùy chọn, bạn chọn một cái để cài.

  • Install Now: Mặc định cài Python vào ổ C, cài sẵn IDLE (cung cấp giao diện đồ họa để làm việc với Python), pip và tài liệu, tạo shortchut,…
  • Customize installation: Cho phép bạn chọn vị trí cài và tính năng cần thiết.

Các tùy chọn cài đặt Python

Mở IDLE. Để tạo file mới trong IDLE bạn nhấp vào File > New Windows hoặc nhấn tổ hợp phím tắt Ctrl + N.

Sao chép đoạn code Python:

 print("Xin chào!") 

vào file vừa tạo, rồi nhấn Ctrl + S để lưu. File sẽ có đuôi là .py, đặt một cái tên cho nó, chẳng hạn: quantrimang-python.py.

Copy code Python vào IDLE

Nhấn Run > Run module hoặc F5 để xem kết quả.

Cài đặt và chạy Python trên Ubuntu

Cài đặt các denpendency sau:

$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

Tải Python tại đây: https://www.python.org/downloads/

Trong terminal, đi đến thư mục chứa file tải về và chạy lệnh sau để giải nén file. Tên file sẽ khác nhau tùy thuộc vào bản bạn tải về.

$ tar -xvf Python-3.6.2.tgz

Đi đến thư mục đã giải nén, nhập lệnh:

$ cd Python-3.6.0

Thực hiện các lệnh sau để biên dịch mã nguồn Python trên Ubuntu.

$ ./configure
$ make
$ make install

Nếu là người dùng mới, bạn nên cài đặt Sublime Text trên máy để viết code Python trên Linux. Nhập lệnh sau để cài:

 $ sudo add-apt-repository -y ppa:webupd8team/sublime-text-2
$ sudo apt-get update
$ sudo apt-get install sublime-text 

Mở Sublime Text, vào File > New File hoặc nhấn Ctrl + N để tạo một file mới.

Lưu file với tên tùy chọn, chẳng hạn quantrimang-python.py

Viết code và lưu nó:

 print("Xin chào!")

Đi đến Tool > Build (Ctrl+B) bạn sẽ nhìn thấy kết quả của dòng lệnh trên ở cuối cửa sổ Sublime Text.

Và như vậy, bạn vừa chạy xong chương trình Python đầu tiên của mình trên Ubuntu.

Cài đặt và chạy Python trên macOS

Tải Python: https://www.python.org/downloads/

Mở file tải về để cài đặt theo hướng dẫn, thông báo cài đặt thành công sẽ hiện ra khi hoàn tất

Bạn có thể sử dụng ứng dụng viết code yêu thích hoặc dùng Sublime Text (công cụ được rất nhiều lập trình viên yêu thích)

Mở trình biên tập code của bạn lên, tạo file mới, lưu với phần mở rộng là .py

Viết code sau và lưu lại:

 print("Xin chào!") 

Tùy thuộc vào trình biên tập code của bạn mà lệnh để chạy code sẽ khác nhau, với Sublime Text thì nhấn Ctrl+B để xem kết quả khi chạy lệnh.

Vậy là đến đây bạn đã tự chạy được lệnh Python đầu tiên rồi.


  1. Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts.
    Anyway I will be subscribing to your feeds and even I achievement you access consistently rapidly.

  2. It’s a pity you don’t have a donate button! I’d most certainly
    donate to this superb blog! I guess for now i’ll settle for
    bookmarking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will talk about
    this site with my Facebook group. Talk soon!

  3. One thing I’d really like to say is tthe fact car insurance
    termination is a terrifying experience so if you’re doig thhe best things being a driver you may not
    get one. Some individuals do obtain the notice thzt tuey have been officially dumped by their own insurance company and sevsral have to fight to gget
    added insurance after a cancellation. Low-cost auto insurance rates are frequently hard
    tto get following a cancellation. Knowing the main reasons concerning the ajto
    insurance termination can help owners prevent burning off
    one of the most crucial privileges available. Thanks for thee tips shared by
    means off your blog.

  4. Undeniably believe that which you stated. Your favorite reason appeared to be
    on the web the simplest thing to be aware of. I say to you, I certainly get annoyed while people consider worries that they just
    don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side-effects , people can take a signal.
    Will probably be back to get more. Thanks

  5. My brother suggested I may like this website.
    He was totally right. This publish actually made my day.

    You cann’t believe just how so much time I had spent for this information!
    Thank you!

  6. What’s Going down i’m new to this, I stumbled upon this I’ve found It positively helpful and
    it has aided me out loads. I hope to give a contribution &
    aid different customers like its helped me. Great job.

  7. Pretty section of content. I just stumbled upon your weblog and in accession capital to assert
    that I get actually enjoyed account your blog posts.

    Anyway I will be subscribing to your feeds and
    even I achievement you access consistently rapidly.

  8. Wow, superb blog format! How lengthy have you ever been blogging for?
    you make blogging glance easy. The total glance of your web site is great, let alone the content!

  9. Excellent post. I was checking constantly this weblog and I am inspired!
    Extremely helpful information particularly the closing section :
    ) I handle such information much. I used to be seeking this certain info for a long
    time. Thank you and good luck.

  10. Oh my goodness! Awesome article dude! Thanks, However I am
    encountering problems with your RSS. I don’t know the reason why I am unable to join it.
    Is there anybody getting identical RSS problems?

    Anyone that knows the answer will you kindly respond? Thanx!!

  11. Whats up this is kinda of off topic but I was wondering if
    blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding knowledge so I wanted to get guidance from someone with experience.
    Any help would be greatly appreciated!

  12. Thank you, I have just been searching for information approximately
    this subject for ages and yours is the best I’ve came upon so far.
    But, what in regards to the conclusion? Are you sure concerning the

  13. Hi, i read your blog from time to time and i own a similar one
    and i was just curious if you get a lot of spam remarks?
    If so how do you reduce it, any plugin or anything you can suggest?

    I get so much lately it’s driving me insane so any assistance is very much appreciated.

  14. My developer is trying to persuade me to move to .net from PHP.

    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using Movable-type on a variety of websites for about a
    year and am worried about switching to another platform.
    I have heard very good things about blogengine.net.
    Is there a way I can transfer all my wordpress content into it?

    Any kind of help would be really appreciated!

  15. What’s up to every body, it’s my first pay a quick visit of
    this webpage; this webpage includes remarkable and genuinely good information in support of readers.

  16. You actually make it seem so easy with your presentation but I find
    this matter to be actually something which I think I would never understand.
    It seems too complex and very broad for me.
    I am looking forward for your next post, I’ll try to get the hang of it!

  17. Hmm it appears like your blog ate my first comment (it was extremely long) so I
    guess I’ll just sum it up what I wrote and say, I’m thoroughly
    enjoying your blog. I too am an aspiring blog blogger
    but I’m still new to everything. Do you have any tips and hints for inexperienced blog writers?
    I’d certainly appreciate it.

  18. Hello there! This post could not be written any better!

    Reading this post reminds me of my good old room mate! He always kept talking about this.
    I will forward this page to him. Fairly certain he will have a
    good read. Thank you for sharing!

  19. My developer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am nervous about switching to another platform.
    I have heard very good things about blogengine.net.

    Is there a way I can import all my wordpress posts into it?
    Any kind of help would be really appreciated!

  20. Admiring the persistence you put into your website and detailed information you offer.
    It’s awesome to come across a blog every once in a
    while that isn’t the same outdated rehashed material.

    Wonderful read! I’ve saved your site and I’m adding
    your RSS feeds to my Google account.

  21. Great site you have here but I was curious if you knew of any
    user discussion forums that cover the same topics discussed in this article?
    I’d really love to be a part of group where I can get advice from other knowledgeable people that share the same
    interest. If you have any suggestions, please let me know.

  22. Fascinating blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple tweeks would really make my blog stand out.
    Please let me know where you got your theme. Bless you

  23. I’m really enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much more pleasant for
    me to come here and visit more often. Did you hire out a designer to
    create your theme? Great work!

  24. I’m amazed, I have to admit. Seldom do I come across a blog that’s both equally
    educative and entertaining, and without a doubt, you have hit the nail on the head.
    The issue is something that not enough people are speaking
    intelligently about. I am very happy I came across
    this in my hunt for something relating to this.

  25. No matter if some one searches for his required thing,
    therefore he/she desires to be available that in detail, therefore that thing is maintained over here.

  26. Hi my loved one! I wish to say that this article is amazing,
    nice written and come with almost all vital infos.
    I would like to see more posts like this .

  27. Aw, this was a really good post. Finding the time and actual effort
    to make a top notch article… but what can I say… I put things
    off a whole lot and don’t seem to get nearly anything done.

  28. I all the time used to study article in news papers but now as I am
    a user of web therefore from now I am using
    net for articles or reviews, thanks to web.

  29. Please let me know if you’re looking for a article writer for
    your site. You have some really good articles and I feel I would be a
    good asset. If you ever want to take some of the load
    off, I’d love to write some material for your blog
    in exchange for a link back to mine. Please shoot me an e-mail if interested.

  30. A person necessarily lend a hand to make severely articles I might state.
    This is the first time I frequented your website page and so far?
    I surprised with the analysis you made to create this actual post
    extraordinary. Magnificent process!

  31. Hello there! Do you know if they make any plugins to safeguard against
    hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any suggestions?

  32. La impotencia sexual es física, es decir, se puede tener el deseo intenso de tener un encuentro sexual, pero o bien no consigues la erección o bien no se mantiene como para completar el acto. Si esta técnica no tiene éxito, puede resultar apropiado recurrir a la terapia del comportamiento sexual.

  33. Tremendous issues here. I am very satisfied to peer your article.
    Thank you a lot and I am taking a look ahead to touch you.
    Will you kindly drop me a e-mail?

  34. This design is wicked! You definitely know how to keep a reader amused.
    Between your wit and your videos, I was almost moved to start my own blog
    (well, almost…HaHa!) Fantastic job. I really enjoyed what you
    had to say, and more than that, how you presented
    it. Too cool!

  35. Having read this I thought it was really informative. I appreciate you spending some
    time and effort to put this short article together.

    I once again find myself spending a significant amount of time both reading and posting comments.
    But so what, it was still worthwhile!


Please enter your comment!
Please enter your name here