I am just starting to set up virtual environments for my Python projects. Up to now I have used and like Geany for development and testing. When I set up my new virtual environment, what will I need to set in Geany to make sure it runs my Python code in the appropriate venv?
Thanks!
Start by creating a project file that resides in your venv
folder. Then, point to the Python interpreter that resides in the venv
folder using the build configuration feature. These actions will allow you to run the correct Python interpreter for each virtual environment you create and not affect the configuration of other virtual environments, other project configurations, or your base configuration.
To set Geany up so that it runs Python code in the appropriate venv
, follow these steps:
1) Verify Geany is set up for Project Sessions. To do this, go to the main menu, select 'Edit', then 'Preferences'. The Preferences window will appear. Select the General Tab, then select 'Miscellaneous' tab. Now look at 'Projects' section on the tab. Verify both 'Use project-based session files' and 'Store project file inside the project-based directory' are selected.
2) Create a Geany project file in your venv
folder. To do this, go to the main menu, select 'Project', then select 'New'. Give the project a name and save it in your virtual environment folder.
3) Configure the build commands for the above project. To do this, go to the main menu, select 'Build', then select 'Set Build Commands'. A window will appear. Look for the 'Execute' button on the bottom left of the window. In the command box next to the 'Execute' button type in the complete path to the bin folder in your venv
folder that contains the Python interpreter you wish to run, then add "%f" to the end of the command. For example, my virtual folder is in home/my_virtual_env_folder
and I want to run the Python3.4 intrepreter in that folder, so I would type in:
/home/virtual_env_folder/bin/python3.4 "%f"
Click 'OK' and the changes you made will be saved. Now when you open the project you just created, the project file will automatically point to the correct Python interpreter for the venv
you are working in.
I am using Windows 10 and conda virtual environments, which I first have to activate before use. I was able to use these conda environments in Geany 1.36 by doing the following:
Go to menu: Edit - Preferences, in there go to Tools tab and in Terminal, type the following:
cmd.exe /Q/C conda activate envname && %c
Go to menu: Build - Set Build Commands, in there go to "Execute commands" section, and in Execute Command, type the following:
python "%f"
In the end it's like you are executing the following (assuming your python file is "script.py"):
cmd.exe /Q/C conda activate envname && python script.py
This worked for me. Just a note, when I installed miniconda, I added it to the PATH variables in Windows 10. That is why I don't have to add the path where the activate.bat or python.exe are located, they are already declared in the PATH variable from Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With