Python how to create a python3.9 venv in freebsd 14 gnome GUI?

dear all :
i have install python3.9 in my freebsd 14 GUI and want to create development python3.9 venv . i got much problems in below .
1. freebsd14 don't have "source" command , so i can't run "source //home/game/python_venv/activate " . freebsd13 have "source" command . freebsd14 don't have it . so i can't run "source //home/game/python_venv/activate " to load python3.9 venv ......
2. create python3.9 venv with command "python3.9 -m venv /home/game/python_venv/" . that is ok. but we can't find deactivate script in /home/game/python_venv/bin/ folder.
if we active python3.9 venv , we don't have deactive command to exit from venv .

anyone can help me ? thanks.
 
First problem, no source command: What shell are you using? If my memory is correct (please check it with the man pages), csh and bash have a source command, while sh does not; sh instead uses the "." command. Bash is not a shell that is installed by the base system on FreeBSD, but it is the most common shell on Linux. I don't remember what the default user shell for new installs on FreeBSD is.

Depending on what shell you are using, you have to use the correct activate script. The one just called "activate" is intended for bash, and I suspect that it won't work correctly with sh. There is one called "activate.csh", which is obviously for csh. There are also versions for the fish shell, and for the Windows PowerShell (named .fish and .ps1, obviously). If you are using the original sh as your shell, I don't know what activate script will work out of the box; you may have to the take the bash version and modify it.

Second problem, no deactivate command: The way venv works is: you run the activate script (using source or a similar mechanism). That script creates a new command called deactivate; depending on the shell, that can be an alias or a function. There is no deactivate script.

But in practice, it is easy to do the deactivate command by hand: All it does is remove the venv from the path, and restore the prompt. Look at your path, and remove the venv directory from it, done.
 
First problem, no source command: What shell are you using? If my memory is correct (please check it with the man pages), csh and bash have a source command, while sh does not; sh instead uses the "." command. Bash is not a shell that is installed by the base system on FreeBSD, but it is the most common shell on Linux. I don't remember what the default user shell for new installs on FreeBSD is.

Depending on what shell you are using, you have to use the correct activate script. The one just called "activate" is intended for bash, and I suspect that it won't work correctly with sh. There is one called "activate.csh", which is obviously for csh. There are also versions for the fish shell, and for the Windows PowerShell (named .fish and .ps1, obviously). If you are using the original sh as your shell, I don't know what activate script will work out of the box; you may have to the take the bash version and modify it.

Second problem, no deactivate command: The way venv works is: you run the activate script (using source or a similar mechanism). That script creates a new command called deactivate; depending on the shell, that can be an alias or a function. There is no deactivate script.

But in practice, it is easy to do the deactivate command by hand: All it does is remove the venv from the path, and restore the prompt. Look at your path, and remove the venv directory from it, done.
dear ralphbsz:
i have used freebsd14 with gnome GUI desktop. from comamnd printenv , i have saw "SHELL=/bin/sh". below was the comamnd line. please check it.

game@ccc222:~/download/python_venv/bin $ ls
activate activate.fish pip pip3.9 python3
activate.csh Activate.ps1 pip3 python python3.9
root@ccc222:/home/game/download/python_venv/bin # sh activate.csh
alias: deactivate: not found
activate.csh: deactivate: not found
activate.csh: setenv: not found
activate.csh: setenv: not found
activate.csh: 26: Syntax error: end of file unexpected (expecting "fi")
root@ccc222:/home/game/download/python_venv/bin # sh activate
root@ccc222:/home/game/download/python_venv/bin #
root@ccc222:/home/game/download/python_venv/bin # source
su: source: not found
root@ccc222:/home/game/download/python_venv/bin #
 
I think that the "activate" script that venv creates (and that you have, see above) will work with sh, even though it says at the top that it is for bash.

There are two problems with your command lines. First, sh does not have a "source" command, instead it uses the "." command. So type ". activate" instead of "source activate". Second, do not use "sh activate", nor "./activate" or some other way of calling it. Why not? Because the activate script changes your current shell environment, and for that to work you have to be inside your current shell, not start a new shell.

Speaking of that: Do you understand what the "sh activate" command would actually do? Do you understand the difference between "source activate" which is the same as ". activate" and "./activate"? If no, please go back and learn about some fundamentals of shells. Without that understanding, you will not be happy using shells (meaning using the command line).
 
I think that the "activate" script that venv creates (and that you have, see above) will work with sh, even though it says at the top that it is for bash.

There are two problems with your command lines. First, sh does not have a "source" command, instead it uses the "." command. So type ". activate" instead of "source activate". Second, do not use "sh activate", nor "./activate" or some other way of calling it. Why not? Because the activate script changes your current shell environment, and for that to work you have to be inside your current shell, not start a new shell.

Speaking of that: Do you understand what the "sh activate" command would actually do? Do you understand the difference between "source activate" which is the same as ". activate" and "./activate"? If no, please go back and learn about some fundamentals of shells. Without that understanding, you will not be happy using shells (meaning using the command line).
thanks sir ralphbasz.
i am new guy in freebsd. do you know how to running active script in my freebsd14 with gnome GUI ? .what ever i try, it;s not work .
 
Read the activate script: all it does is prepend the bin directory of the venv to the path. In a nutshell, that amounts to:
Code:
export PATH=/directory/of/venv/bin:$PATH
All the rest of the activate script is cosmetics. You can just run that line yourself. To execute the whole script, just say ". /directory/of/venv/bin/activate".
 
I usually do the following steps:

Code:
python3.9 -m venv venv # Create venv directory
. ./venv/bin/activate # Activate virtual env
 
Read the activate script: all it does is prepend the bin directory of the venv to the path. In a nutshell, that amounts to:
Code:
export PATH=/directory/of/venv/bin:$PATH
All the rest of the activate script is cosmetics. You can just run that line yourself. To execute the whole script, just say ". /directory/of/venv/bin/activate".

Dear ralphbsz. your solution is not work. thanks for your help . i will find other way . thanks.
game@de:~/program/python_app/py_venv/bin $ cat activate
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
..........................................

now freebsd 14 don't have source of builtin program .
 
I usually do the following steps:

Code:
python3.9 -m venv venv # Create venv directory
. ./venv/bin/activate # Activate virtual env
dear hhartzer. thanks . i have used freebsd14 with gnome GUI. your solution is not work . please see my first question.
 
it does not work with /bin/sh out of the box. Either you change the activate script yourself, or, and this is my recommendation: use another shell, like /bin/csh or tcsh and use activate.csh or /usr/local/bin/{bash,zsh} (provided you have bash/zsh installed) and use activate ... or install fish (/usr/local/bin/fish) and use activate.fish. More info: https://docs.python.org/3/library/venv.html
 
Back
Top