tadm123 tadm123 -4 years ago 117
Python Question

(Python) Virtual env and Scrapy

I'll try to explain this, hopefully it makes sense.

I had installed a virtual env a while ago in the directory:

desktop/project_website/test_project/env
to do some websites.

I also installed scrapy on the
desktop/project_website/test_project/env/Scripts
dir.

The problem is that whenever I use the command prompt to run scrapy I need to be in this specific directory, so all the files that scrapy creates are made in here, not in the directory where my project is (that is
desktop/project_website/Scrapy
)

So how would I would I be able to run scrapy in the dir that I want? Thanks.

Answer Source

You can create virtualenv in any directory:

virtualenv some/directory
# or windows
virtualenv some\directory

Then you can activate that virtualenv which will change your $PATH environment variables to read python related things from virtual environments directory instead of your system's:

source some/directory/bin/activate
# or for windows
some\directory\Scripts\activate

and to deactivate type: deactivate

See more at official documentation of virtualenv

Once you have virtualenv activated when you call scrapy the scrapy of virtual environment will be called instead of system one and any packages you install via pip(if the python version in your virtualenv has it) will be installed to the virtual environment.
You can always test what will run by using:

$ which scrapy
some/directory/bin/scrapy
# or for windows
$ where scrapy
some\directory\bin\scrapy
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download