Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Perl script: run Python env activate script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Vieri
l33t
l33t


Joined: 18 Dec 2005
Posts: 895

PostPosted: Wed Oct 16, 2024 5:20 pm    Post subject: Perl script: run Python env activate script Reply with quote

Hi,

I'd like a Perl script to properly run a program within a Python virtual environment and retrieve its stdout text.

Something like:

Code:
`source /opt/custom_pyvenvs/program/bin/activate param1 param2'


If I try to run this in Perl I get a "source: No such file or directory" error.

I know source is a BASH built-in command, so can I run the "activate" script directly from the Perl script within a bash shell even though the activate script is supposed to be "sourced"?

Regards,

Vieri
Back to top
View user's profile Send private message
bstaletic
Guru
Guru


Joined: 05 Apr 2014
Posts: 342

PostPosted: Wed Oct 16, 2024 5:31 pm    Post subject: Reply with quote

Sourcing a bash script in a perl interpreter makes no sense.
On the other hand, replicating what the activate script does is almost trivial:


  • Define $VIRTUAL_ENV to be the root directory of the virtual environment
  • Prepend $VIRTUAL_ENV/bin to $PATH
  • Mess with your $PS1
  • Define deactivate function to undo everything.


I'm sure perl has its way of altering the environment.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum