GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • About
  • Learn Python
  • Archives
  • Contact
  • Python Videos, Tutorials and Screencasts
  • HTML
  • PDF
  • Further Python 3 docs
  • Dive Into Python 3
  • Google
  • Youdao
  • Xian Guo
  • Zhua Xia

This view

  • Original page
  • New address

GeezerVison is showing pythonadventures.wordpress.com — tutorial – Python Adventures

Python Adventures

Welcome to the Jungle!
  • Home
  • About
  • Learn Python
  • Archives
  • Contact

Archive

Posts Tagged ‘tutorial’

moving from pipenv to poetry

November 2, 2019 Jabba Laci Leave a comment

In the past 1-1.5 years I’ve used pipenv, which worked very well for me but it was annoyingly slow. Creating a virtual environment took a minute sometimes, and installing the dependencies often took several minutes. I’ve heard lots of good things about poetry, so I decided to give it a try. After reading its documentation, I could do everything with it that I needed, so in the future I’ll use poetry for managing my virtual environments.

Getting started
The home page of poetry is here.

The installation is a bit speacial: https://poetry.eustace.io/docs/. After the installation, open a new terminal and issue the command “poetry“. If it starts, then the installation was successful :)

The installer puts poetry in the folder ~/.poetry .

By default, new virtual environments are put in the folder ~/.cache/pypoetry/virtualenvs/. However, I prefer collecting the virtual environments in ~/.virtualenvs. For this, issue the following command:

$ poetry config settings.virtualenvs.path $HOME/.virtualenvs

Actually, it’s a good idea to put this value in an environment variable too. Add this line to the end of your ~/.bashrc file:

export WORKON_HOME=$HOME/.virtualenvs

The config info is stored in the file ~/.config/pypoetry/config.toml .

Update poetry

poetry self:update

Use case #1: Create a new poetry project from scratch

$ mkdir demo
$ cd demo
$ poetry new [--src] .

It will create the basic structure of a new project (scaffolding). If you want to store the source files in the directory “src/“, then add the option “--src“. The dot at the end means the current directory.

Create / activate / deactivate the virtual environment

poetry shell

If the virt. env. doesn’t exist yet, poetry will create it. For this to work, you need to have the file pyproject.toml .
If the virt. env. exists, then “poetry shell” will activate it. Actually, it opens a subshell.
To deactivate the virt. env., simply close the subshell (with Ctrl-D for instance).

Install / remove a package

poetry add requests [--dev]

It’ll install the given dependency (requests in the example) and add it to your pyproject.toml file. With the option “--dev“, the package will be installed as a development dependency.

poetry remove requests

Remove the package and if it installed some sub-dependencies, then those packages are also removed.

Help
Simply launch “poetry” to see all the options. To get help about an option, e.g. about “install”, then use this:

poetry help install

Show installed packages

$ poetry show [--no-dev]
$ poetry show --tree [--no-dev]

Show the list of installed packages. With “--tree“, show the result in a tree layout. With “--no-dev“, development packages will be hidden.

Version control
Upload both pyproject.toml and poetry.lock in your version control system.

Where is the directory of the virtual environment?
To figure out the directory of the virt. env., use the command

poetry show -v

and the result will be in the first line. If you need just this information, then here is how to extract it:

venv_folder=`(poetry show -v | head -1) 2>/dev/null | cut -d" " -f3`

Which packages are outdated?

$ poetry show -o
$ poetry show --outdated    # same thing

It will show which packages have newer versions.

Update a package / all packages

$ poetry update requests

Update the given package. However, it takes into account the SemVer rules, defined in pyproject.toml . Read more about versioning here: https://poetry.eustace.io/docs/versions/.

poetry update

Update all packages. Again, it follows the SemVer rules.

Edit your pyproject.toml
If you edit the .toml file, you can verify it with

poetry check

Use case #2: Convert an existing project to a poetry project
All right. Say you have a project and you want to convert it to a poetry project. For example it was managed by pipenv but you want to switch to poetry. Here are the steps:

  • enter the project directory
  • “poetry init -n” will create a pyproject.toml file without asking any embarrassing questions. Review this file if you want. For instance, set the proper Python version.
  • “poetry shell” — create a virt. env. for the project
  • “poetry add pkg1 pkg2” — install the given packages (copy them from your Pipfile, for instance)
  • “poetry add pkg1 pkg2 --dev” — install the development packages

Use case #3: Checkout a poetry project
Let’s say you download a project from GitHub and it uses poetry, i.e. it has a pyproject.toml file and possibly a poetry.lock file too. How to create a virt. env. for it? How to install its packages? Aaaargghhhh!

Relax and issue this simple command inside the project folder:

poetry install [--no-dev]

By default, it also installs the development packages. Use “--no-dev” if you don’t need the dev. packages.

Windows support
Poetry works under Windows too. The installation is the same. I had to install curl for Windows, but then I could download the installer without any problem.

The installer adds the folder %USERPROFILE%\.poetry\bin to your PATH.

The virtual environments are created here: %USERPROFILE%\AppData\Local\pypoetry\Cache\virtualenvs\ .

Unfortunately, when I activated a virt. env., the prompt didn’t change.

Troubleshooting

Under Ubuntu 18.04 I had to use some tricks to force poetry to use Python 3. Find the details here. In short: edit the file ~/.poetry/bin/poetry and update its first line to #!/usr/bin/env python3. If you update poetry, it’s very likely you’ll have to change this file again.

Links

  • How to Rock Python Packaging with Poetry and Briefcase
Categories: python Tags: pipenv, poetry, tutorial

Posts on Python and Big Data

June 6, 2013 Jabba Laci Leave a comment

See Neal Caren’s tutorials and posts on Python and Big Data here: http://nealcaren.web.unc.edu/big-data/.

Categories: python Tags: big data, tutorial

install gevent

May 7, 2012 Jabba Laci Leave a comment
sudo apt-get install libevent-dev python-all-dev
sudo pip install gevent 

Nice tutorial on gevent: here.

Categories: python, ubuntu Tags: gevent, install, tutorial

Video tutorials at marakana.com

August 13, 2011 Jabba Laci Leave a comment

“Marakana‘s raison d’être is to help people get better at what they do professionally. We accomplish this by organizing software training courses (both public and private) as well as publishing learning resources, sharing knowledge from industry leaders, providing a place to share useful tidbits and supporting the community. Our focus is open source software.”

Their Python videos are here.

Categories: python Tags: marakana, training, tutorial, video, video tutorial

Python video tutorials

March 16, 2011 Jabba Laci Leave a comment

Some video tutorials:

  • TheNewBoston – Free Educational Video Tutorials on Computer Programming and More! » Python
  • Python Videos, Tutorials and Screencasts

Ref.: python-list mailing list.

Categories: python Tags: tutorial, video

Python tutorials at IBM developerWorks

February 28, 2011 Jabba Laci Leave a comment

IBM developerWorks has great tutorials. Check out their Python tutorials.

Categories: python Tags: ibm, tutorial

Python tutorials of Full Circle Magazine in a single PDF

February 21, 2011 Jabba Laci Leave a comment

On my other blog, I wrote a post on how to extract the Python tutorials from Full Circle Magazine and join them in a single PDF.

For the lazy pigs, here is the PDF (6 MB). Get it while it’s hot :)

Categories: python Tags: full circle magazine, pdf, tutorial

Should I use Python 2 or Python 3?

February 4, 2011 Jabba Laci Leave a comment

“Should I use Python 2 or Python 3?”

This is a very common question when someone wants to learn Python. Here is a nice article about this topic: http://wiki.python.org/moin/Python2orPython3.

(Thanks Jaume for the link.)

Update (20110404)

If you are ready to dive in Python 3, here are some tutorials:

  • The official Python 3 tutorial (HTML, PDF)
  • Further Python 3 docs (c-api.pdf, distutils.pdf, documenting.pdf, extending.pdf, faq.pdf, howto-advocacy.pdf, howto-cporting.pdf, howto-curses.pdf, howto-descriptor.pdf, howto-doanddont.pdf, howto-functional.pdf, howto-logging-cookbook.pdf, howto-logging.pdf, howto-pyporting.pdf, howto-regex.pdf, howto-sockets.pdf, howto-sorting.pdf, howto-unicode.pdf, howto-urllib2.pdf, howto-webservers.pdf, install.pdf, library.pdf, reference.pdf, tutorial.pdf, using.pdf, whatsnew.pdf)
  • Dive Into Python 3 (HTML and PDF)

Update (20110526)

I follow the following simple guideline: I use that version of Python that comes with Ubuntu by default. In Ubuntu 10.10 it was Python 2.6, in Ubuntu 11.04 it’s Python 2.7. When they switch to Python 3.x, I will switch too.

Categories: python Tags: dive into python 3, documentation, python2, python3, tutorial
RSS feed
  • Google
  • Youdao
  • Xian Guo
  • Zhua Xia
  • My Yahoo!
  • newsgator
  • Bloglines
  • iNezha

Blog Stats

  • 1,659,944 hits

Random Post

Click here for a random post

Recent Posts

  • Get the value of PI without a constant
  • In a graph, find the largest complete subgraph
  • How to solve a two-variable equation with Sympy
  • Autoformat your Python code with Ruff
  • Play a sound file from memory

ascii bash beautifulsoup book bpython challenge command-line convert cron crontab date datetime distance dropbox email eric exercise extract file firefox github google hacking heroku html ide imdb imgur install ipython java jinja2 json linux module modules MongoDB movies news pdf perl pi pip print pylint pypi python3 python shell quote readline reddit redirect refactoring regexp requests reverse review shell sound stdout string tab text threads time tip tutorial unicode url video virtualenv virtual environment virtualenvwrapper xml zip

Archives

  • December 2025 (1)
  • December 2024 (2)
  • March 2024 (1)
  • February 2024 (3)
  • June 2023 (1)
  • December 2022 (1)
  • May 2022 (1)
  • March 2022 (1)
  • February 2022 (2)
  • October 2020 (3)
  • September 2020 (2)
  • July 2020 (1)
  • December 2019 (1)
  • November 2019 (7)
  • June 2019 (2)
  • May 2019 (1)
  • February 2019 (1)
  • January 2019 (1)
  • August 2018 (1)
  • July 2018 (4)
  • June 2018 (5)
  • May 2018 (1)
  • March 2018 (2)
  • February 2018 (1)
  • January 2018 (2)
  • December 2017 (2)
  • October 2017 (1)
  • August 2017 (1)
  • May 2017 (2)
  • April 2017 (1)
  • March 2017 (1)
  • February 2017 (3)
  • January 2017 (5)
  • December 2016 (3)
  • October 2016 (2)
  • September 2016 (1)
  • August 2016 (4)
  • July 2016 (3)
  • June 2016 (2)
  • May 2016 (2)
  • April 2016 (1)
  • March 2016 (4)
  • February 2016 (1)
  • January 2016 (4)
  • December 2015 (5)
  • November 2015 (8)
  • October 2015 (2)
  • September 2015 (3)
  • August 2015 (6)
  • July 2015 (4)
  • June 2015 (1)
  • May 2015 (3)
  • April 2015 (2)
  • February 2015 (1)
  • January 2015 (6)
  • December 2014 (5)
  • November 2014 (2)
  • October 2014 (1)
  • September 2014 (1)
  • August 2014 (14)
  • July 2014 (3)
  • June 2014 (6)
  • May 2014 (3)
  • April 2014 (2)
  • March 2014 (4)
  • February 2014 (3)
  • January 2014 (19)
  • December 2013 (8)
  • November 2013 (9)
  • October 2013 (4)
  • September 2013 (10)
  • August 2013 (16)
  • July 2013 (4)
  • June 2013 (7)
  • May 2013 (7)
  • April 2013 (3)
  • March 2013 (12)
  • February 2013 (2)
  • January 2013 (10)
  • December 2012 (18)
  • November 2012 (3)
  • October 2012 (4)
  • September 2012 (5)
  • August 2012 (1)
  • July 2012 (1)
  • May 2012 (8)
  • April 2012 (9)
  • March 2012 (17)
  • February 2012 (3)
  • January 2012 (8)
  • November 2011 (11)
  • October 2011 (7)
  • September 2011 (17)
  • August 2011 (5)
  • June 2011 (1)
  • May 2011 (7)
  • April 2011 (21)
  • March 2011 (21)
  • February 2011 (7)
  • December 2010 (4)
  • November 2010 (1)
  • October 2010 (16)
  • September 2010 (15)

Meta

  • Create account
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
  • Python Adventures
    View site in Reader
    Manage subscriptionsSign upLog in
    Report this content
    Collapse this bar
Loading Comments...

You must be logged in to post a comment.

Create your own website, free on WordPress.com.Create your own website.
Start free
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.