New Project¶
Step 5: Test that git, pyenv, poetry work:
What is the plan?
- On Windows it is very easy to install something improperly. Only by testing after an install you can verify something is installed correctly.
- Here we will clone a git repo of a "Hello world!" kivy project named KivyTest that only works on python 3.8. We will be using VS Code for screenshots and as an example editor.
Quick Hello world!
kivy app installation and run
- Make a new folder called "KivyProjects" to hold your projects
How do I make a new folder in Windows?
- You can right click on an empty space in the folder of your choice and click "New > Folder"
- In VS Code, use the default shortcut to bring up a new terminal
CTRL + J
- Check if the terminal is in the folder you want to create your subfolder
- If you need to change directory, the command is
cd <folder location>
- In your VS Code terminal, type
mkdir "KivyProjects"
- You can also press ⊞ Windows key, type
cmd
and entercd "Your folder location"
to a folder of your choice - In your terminal, type
mkdir "KivyProjects"
- Open VS Code, and open the KivyProjects folder (File > Open > Folder > KivyProjects)
-
Open a new terminal in VS Code using
CTRL + J
-
Clone the GitHub repo by typing in the terminal:
git clone https://github.com/ShootingStarDragon/Kivy-3.9.5
- Open the Kivy-3.9.5 folder with VS Code (File > Open > Folder > Kivy-3.9.5)
- Check VS Code terminal, it should by default be in your Kivy-3.9.5 folder. You can always move your terminal inside that folder by typing:
cd "location of folder Kivy-3.9.5"
- In the VS Code terminal, type
poetry install
- It should show an error unless your system python is already 3.9.5.
The currently activated Python version 3.9.0 is not supported by the project (3.9.5). Trying to find and use a compatible version. [WinError 2] The system cannot find the file specified
- To fix this, we will install the right version of python with pyenv, then tell poetry to use python 3.9.5 and run the program as it was intended.
- Install python 3.9.5 with pyenv:
pyenv install 3.9.5
- Now, check where pyenv installed python 3.9.5.
- Using a new terminal, type:
pyenv shell 3.9.5 pyenv which python
- Copy this directory path for the next step.
- Delete the .venv folder in the Kivy-3.9.5 folder if it was made.
- Next in your project folder in VS Code type
poetry env use "the location you found for python 3.9.5"
Too many arguments!
If your filepath has spaces, you must use quotes to surround your filepath so that you do not get an error, else you will see:
Too many arguments to "env use" command, expected arguments "python"
- The terminal will say
Creating virtualenv...
- Once the terminal is done, VS Code may ask in the bottom right (if the option has not been set already):
- Click yes. This allows VS Code to run your python files with the right version of python and running a python file with the
F5
key. You can always run any python file from within apoetry shell
instance of the terminal usingpython filelocation.py
- If VS Code shows this, click to "Debug the currently active Python file"
- In your terminal, type to install dependencies and libraries for this project:
poetry install
- In your terminal, type:
poetry shell
What is a virtual environment?
A virtual environment is used to separate your work on a project from your base operating system. This is so that different python versions don't conflict, and make it harder for version conflicts to happen. The worst case scenario is that you install everything in your base Windows system. This is a problem because one project might need a dependency like OpenCV and python 3.7 to work, but in another project a dependency wants python 3.10. You will get a lot of headaches trying to sort out versions. Instead, separate them in virtual environments away from your operating system to save yourself the trouble.
With Poetry, you type poetry shell
in your project's folder so that you interact with python and the dependencies listed for that project only, NOT the version of python that is installed in your base OS.
- Now that you type poetry shell, you will see your project on the left side of the terminal:
(kivy3-9-5-py3.9)
python main.py
main.py
in VS Code and press F5
.
- Hello world!