titusAdam
titusAdam

Reputation: 809

Python: install module on correct path in OSX

I'm trying to use scrapy with python 2.7. I've installed scrapy succesfully, but when I try to import the module I get a message saying "unknown module".

So I have some super basic questions regarding installing python modules in pycharm:

1) How do I make sure that a module is installed on the correct project path? I spent a week recently installing pyqt4 and I really want to get a good understanding of how directories/paths work, so that I don't have to enter random commands in my terminal and hope I get lucky.

2) Why is it possible to install some modules directly through Pycharm in the project interpeter and do you need to install others manually with pip or homebrew?

Thanks in advance!

Upvotes: 0

Views: 2044

Answers (1)

Muntaser Ahmed
Muntaser Ahmed

Reputation: 4647

The default location for packages installed via pip for Python 2.7 on Mac OS X is /Library/Python/2.7/site-packages/.

You can see where packages are located using pip show <package_name>. For example, if I wanted to know where my requests package is located, I would run pip show requests.

  1. If you are running a python script using Python 2.7, the packages you are referencing should exist in the path mentioned above (if the packages are installed correctly). If you want to maintain more control over your projects and their packages/versions, you should use virtualenv. Virtualenv creates environments that have their own installation directories that don't share packages with other virtualenv environments. This is a very popular option many people use when managing projects.
  2. Most packages should be installable across PyCharm and pip as they both look to the Python Package Index (PyPI) as their repository by default. Make sure you don't have another repository set if you want results from pip and PyCharm to be consistent.

Hope this helps!

Resources:

  1. pip show
  2. virtualenv
  3. PyPI

Upvotes: 1

Related Questions