Starting a new Python project is quick once you know the steps. First, you’ll need Python 3. There are a few easy ways to get it:
-
The official installer at https://www.python.org/downloads/
-
A package manager like Homebrew on macOS, or apt-get on Linux.
Got Python 3 ready? Let’s set up a project.
Create a Python virtual environment
I like to keep each project’s dependencies separate, so I always start with a virtual environment:
mkdir my-python-app
python3 -m venv my-python-app
Activate the virtual environment
Now turn it on:
source my-python-app/bin/activate
Once it’s active, your Terminal prompt changes to something like this:
(my-python-app) $
From here, any python3 or pip3 command you run stays inside this environment.
For example, let’s install the boto3 package:
(my-python-app) $ pip3 install boto3
Hello Python World
Time for a quick “Hello World”. Create a new file called main.py:
(my-python-app) $ vim main.py
And drop in this code:
def main():
print("Hello World")
if __name__ == "__main__":
main()
Then run it:
(my-python-app) $ python3 main.py
Deactivate the virtual environment
When you’re done, just switch it off:
(my-python-app) $ deactivate
Happy coding !