1

I have python2( as default environment) and python3 installed on redhat server and set up different alias for them.

.bashrc

alias myconda='export PATH="/root/anaconda3/bin:$PATH"'

I activate this alias by executing myconda on terminal. How can I activate it using python script as I need to run scrapy spider on python3?

Update: I want to integrate scrapy spider with flask as API. When POST method hit the endpoint url, then I want to run the scrapy spider. Currently spider runs fine individually.

I am trying to activate bash alias like this -

import subprocess
subprocess.Popen('myconda;scrapy crawl company_pro;', shell=True)

This doesn't identify myconda as alias and uses default python2 environment instead of python3 to start spider and gives python2 syntax errors and

/bin/sh: myconda: command not found. error

Thanks in advance.

1
  • This is a common FAQ. The absolutely simplest and most preferred solution is to not use an alias for this in the first place (or, more generally, at all). Commented Mar 10, 2018 at 12:29

1 Answer 1

0

If I am not misunderstanding your requirement, how about use following:

python -m scrapy startproject xxx

You can choose your python still by environment or just use full path?

Sign up to request clarification or add additional context in comments.

1 Comment

This does not solve my issue. I solved using subprocess.call(['/bin/bash', '-i', '-c', 'myconda;scrapy crawl company_pro;']). The -i flag is for interactive mode for bash.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.