6

Trying to open a python3 virtual environment I have created with

python3 -m venv myVenv

by doing

source myVenv/bin/activate

as I do in Linux, but I get

ksh: source: not found

which mean it is not in my path/installed. When I try to add it with pkg_add, it just tell me it can't find it. Does OpenBSD use something else that allows me to use venv or what should I do?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Salviati
  • 189
  • 1
  • 12
  • `source` is a `bash` command. To switch to `bash` as your login shell, if this would make your life easier, install the `bash` port/package and update your login shell with `chsh`. `bash` would be installed as `/usr/local/bin/bash` on OpenBSD. – Kusalananda Mar 04 '19 at 17:42

3 Answers3

19

You are using the Forsyth PD Korn shell, the usual login shell on OpenBSD. The PD Korn shell does not have a source command. The source built-in command is only available in some shells. The command that you want is the . command.

Further reading

JdeBP
  • 66,967
  • 12
  • 159
  • 343
10

The source keyword which is available in bash is not part of the Posix standard. Instead you can use

. myVenv/bin/activate

You could use the same syntax with . in bash which you are using on your Linux system.

Bodo
  • 5,979
  • 16
  • 27
1

As an alternative, you can simply launch a new bash shell, and source it there:

ksh$ bash
bash$ source myVenv/bin/activate
(myVenv) bash$ python ...

As a bonus, this gives you an easy way to deactivate the venv and return to a pristine environment: just exit from the bash shell and you'll return to ksh!

Daniel Pryden
  • 209
  • 1
  • 6