0

I have quite a few versions of python installed (running macOS). I installed scrapy with pip install scrapy, and it succeeded. When I use it e.g.

scrapy startproject newProject

I see ModuleNotFoundError: No module named 'six', indicating that I need to install that module (six).

Note: I could easily fix the specific error by installing six for all versions of python installed, but solving that problem isn't what I'm trying to work out here.

Specifically what I'm after here is how to know what version of python a command line utility is using when it runs?

stevec
  • 41,291
  • 27
  • 223
  • 311
  • run `python -V` learn more: https://stackoverflow.com/questions/8917885/which-version-of-python-do-i-have-installed – RayB Dec 11 '20 at 02:54
  • Thanks @RayB I always knew of `python -V` but didn't know for sure if python CLI programs (like scrapy) would always default to that python version given with `python -V`. If it's as simple as that, please make it an answer – stevec Dec 11 '20 at 02:55
  • @RayB I see [here](https://stackoverflow.com/a/5846177/5783745) that I shouldn't change that default version. My default is 2.7, but I want scrapy to use 3.9. I have `python -V .. 2.7` and `python3 -V .. 3.9`. Do you know how I can make `scrapy` (terminal) commands run on python 3.9? – stevec Dec 11 '20 at 02:58
  • Seems I don't need to change the default version, but I can simply tell the CLI which version of python to use with [this method](https://stackoverflow.com/a/44074448/5783745). I have no idea if that generalises to other python CLIs, or if it's just for scrapy – stevec Dec 11 '20 at 03:03

2 Answers2

1

pip install will install package under pythonxxx/site-packages, the concrete location is up to which python version the pip used.

use pip -V to see the pip path and the related Python version. For you question, missing six module, pip install six should be enough, which will install six to the same Python version of scrapy.

After install scrapy, we could also enter scrapy shell, and use the below code to see where scrapy is

scrapy.__file__
Jacky1205
  • 3,273
  • 3
  • 22
  • 44
  • `zsh: command not found: scrapy.__file__` – stevec Dec 11 '20 at 03:20
  • You should enter `scrapy shell` first, and in the scrapy shell, type `scrapy.__file__` – Jacky1205 Dec 11 '20 at 03:21
  • Ah good to know. Unfortunately the scrapy shell won't work for me (which is what initially prompted the question above). But good to know in any case. – stevec Dec 11 '20 at 03:23
  • `pip -V` will give you the the python version and `site-package` path. You could see scrapy in the `site-package` directory. – Jacky1205 Dec 11 '20 at 03:29
  • Also good to know. Another problem with that though, is that I installed both `pip install scrapy` *and* `pip3 install scrapy` :) – stevec Dec 11 '20 at 03:30
  • I guess you might also have python and python3, you could use `python -m scrapy` or `python3 -m scrapy` to launch scrapy based on which version you want. – Jacky1205 Dec 11 '20 at 03:32
1

To check the version of python from within a script or the REPL you can use the sys module.

For example:

>>> import sys
>>> sys.version
'3.8.5 (default, Jul 21 2020, 10:48:26) \n[Clang 11.0.3 (clang-1103.0.32.62)]'
dnx
  • 21
  • 4