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 8182167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:46:09+00:00 2026-06-07T00:46:09+00:00

from fabric.api import sudo, put, run def install(): run(‘source /home/user/.virtualenvs/demo/bin/activate’) run(‘pip install requests’) if

  • 0
from fabric.api import sudo, put, run

def install():
    run('source /home/user/.virtualenvs/demo/bin/activate')
    run('pip install requests')

if __name__ == '__main__':
    install()
# to run this, do fab fabfile

Q1.
I want to install pip in that environment. But after the script ran, requests is not install in the virtualenv. Why?

Q2. I am asked to provide host information (the following is also the log for Q1). If my goal is to run on local, is there a better way to handle this?

No hosts found. Please specify (single) host string for connection: localhost
[localhost] run: source /home/user/.virtualenvs/demo/bin/activate
[localhost] Passphrase for private key: 
[localhost] Login password: 
[localhost] run: pip install requests
[localhost] out: Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/dist-packages
[localhost] out: Requirement already satisfied (use --upgrade to upgrade): certifi>=0.0.7 in /usr/local/lib/python2.7/dist-packages (from requests)
[localhost] out: Requirement already satisfied (use --upgrade to upgrade): oauthlib>=0.1.0,<0.2.0 in /usr/local/lib/python2.7/dist-packages (from requests)
[localhost] out: Requirement already satisfied (use --upgrade to upgrade): chardet>=1.0.0 in /usr/lib/python2.7/dist-packages (from requests)
[localhost] out: Requirement already satisfied (use --upgrade to upgrade): rsa in /usr/local/lib/python2.7/dist-packages (from oauthlib>=0.1.0,<0.2.0->requests)
[localhost] out: Requirement already satisfied (use --upgrade to upgrade): pyasn1>=0.0.13 in /usr/local/lib/python2.7/dist-packages (from rsa->oauthlib>=0.1.0,<0.2.0->requests)
[localhost] out: Cleaning up...
[localhost] out: 

Update

I can install the packages in a single run command. Is there a better way to do that?

Thanks.


Here is the update code:

from fabric.api import sudo, put, run
from fabric.context_managers import prefix

def install():
    with prefix('source /home/user/.virtualenvs/demo/bin/activate'):
        run('pip install requests')

if __name__ == '__main__':
    install()

http://docs.fabfile.org/en/1.2.0/api/core/context_managers.html?highlight=prefix#fabric.context_managers.prefix

  • 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-06-07T00:46:11+00:00Added an answer on June 7, 2026 at 12:46 am

    Each fabric.run command spawns a separate subshell in which the command is executed.

    If you activate virtualenv in one of your run commands, the environment is not available for subsequent command execution in a separate invocation of run command.

    See the following discussion on stackoverflow for the correct solution:

    • Activate a virtualenv via fabric as deploy user

    Checkout the usage of contextmanager to run commands with virtualenv activated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from fabric.api import env, sudo def get_hostname(): env.hosts = ['user@host_ip'] env.passwords = {'user@host_ip': 'password'}
Giving the following fabfile: from fabric.api import env, run env.user = 'implicit_user' env.hosts =
The code I'm trying to run: from fabric.api import * from fabric.contrib.files import *
I have the following fabfile.py: from fabric.api import env, run host1 = '192.168.200.181' host2
The following script: #!/usr/bin/env python from fabric.api import env, run import logging logging.getLogger().setLevel(logging.INFO) env.host_string
I want to use Fabric.api.run to directly start an application in a remote box.
I'm using a custom object extended from fabric.Image in my canvas, as suggested in
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
From the Scala API , I got the following example, which does not compile;
From time to time I run into the issue that Grails integration tests the

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.