Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7664907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:25:26+00:00 2026-05-31T14:25:26+00:00

I am trying to activate my virtualenv using a php script or a python

  • 0

I am trying to activate my virtualenv using a php script or a python script but without using SSH.

This is to allow my website.com/something.py file to access certain libraries (if this can be done in another simpler way please let me know)

My PHP code is:

<?php
echo "A";
$result = exec("source ENV/bin/activate");

if ($result){
echo "Worked";
}
else{
echo "didnt work";
}

echo "B";
$result = system("python test.py");

?>

and I have test.py =

def main():
    print "hello"

    try:
        import xlrd
    except:
        try:
            print "xlrd didnt load"
            import MySQLdb
        except:
            print "mdb,xlrd didnt load"


main()

The virtualenv I have setup has xlrd installed.
This is the output I get on the webpage:

Adidnt workBhello xlrd didnt load

It makes sense that xlrd didnt load but why is the source command not working? This all works in SSH

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:25:28+00:00Added an answer on May 31, 2026 at 2:25 pm

    According to the docs, sourcing the activate script inside a shell just tweaks the $PATH environment variable to point to the virtualenv’s bin directory. This script can’t work from PHP, because an external executable can never modify the caller’s environment for security reasons.

    The documentation also tells you what you can do instead:

    If you directly run a script or the python interpreter from the
    virtualenv’s bin/ directory (e.g. path/to/env/bin/pip or
    /path/to/env/bin/python script.py) there’s no need for activation.

    So you can just specify the full path to the Python installation instead:

    $result = system("ENV/bin/python test.py");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an environment using virtualenv. virtualenv test New python executable in
I am trying to activate my Virtual Python Environment to use with Pylons but
Am trying to change text of an asp:Button using jQuery Like this $(#<%=delButton.ClientID%>).attr('text', 'InActivate');
I'm trying to give website admin ability to activate /deactivate or unlock multiple users
I'm trying to activate a self-made wordpress plugin but am getting a T_Variable error
I'm trying to include this Regex condition and activate the analytics code (if it
I've been using virtualenv on Ubuntu and it rocks, so I'm trying to use
I am trying to create a boostrap.py script that will create a virtualenv and
I am trying this simple GUI script to open a new window of Safari:
I'm trying to install and activate ImageMagick with Zend Server (on Ubuntu Server Linux),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.