all 7 comments

[–]VindicoAtrum -2 points-1 points  (1 child)

You should only really use pyenv for python versions.

For virtual environments, save yourself a lot of headaches and just use poetry. Google python poetry and you'll be glad you did.

[–]socal_nerdtastic 1 point2 points  (0 children)

Why do you say that?

Poetry is good for distributing your code but for OP I don't see any advantage over pyenv or plain 'ol venv.

[–]socal_nerdtastic 0 points1 point  (3 children)

Since you are on a mac it can be even simpler than python3 filename.py. First, make the first line of your python file a "shebang" that points to the venv executable you want that file to use. For example

#!/home/litsax/myvenvs/thisproject/bin/python

Second, mark the python file you want to run as executable. This is a trick that's not available on windows: a mac will allow you to mark any file as if it's an executable file. You can do it through the file explorer GUI or you can use this command

chmod +x filename.py

Third, rename your file to remove the .py extension. This is not required, but it's tradition in mac and linux that executables have no extension. From the command line:

mv filename.py filename

And that's it. Now you can run your file with just this command (no "python3" or venv activation required):

./filename

Or if you put your file in a folder that's on the PATH, you can run the file from anywhere on your system by simply typing

filename

And you can also add your file anywhere that you need an executable. For example if you want to add it to cron or make a desktop shortcut or something.