Why are different python modules installed in different locations? - python

I just found something strange and don't know how to fix it. I found a kludge of a workaround though but would rather not do this if I can help it.
I am working on a MBP 10.9.5. I upgraded pip to 9.0.1 from 8.0.1. Then I installed three modules (four if you count the required module)
image
pillow
py2app (required macholib, which it installed automatically)
After the modules are installed, I run pip show on them to see what the locations are.
For some reason, image, pillow and macholib are all installed at
/usr/local/lib/python2.7/site-packages
whereas py2app is installed at
/Library/Python/2.7/site-packages
Do we know why python is splitting up where the modules are installed? The workaround is to go into /usr/local/lib/python2.7/site-packages and copy the directories of these modules to /Library/Python/2.7/site-packages. However, I'd like to avoid doing this if possible and tell pip to install everything in one location rather than wherever it feels like.
There are no config files found for pip (I can list the dirs I looked at if needed) and if there are secret hidden config files, that doesn't explain why pip is installing module files to multiple locations.
Can anyone tell me why this is happening and how to stop it from happening?
Thanks

If /usr/local/lib/python2.7/site-packages is not in your sys.path when you start python, you could find the file named sitecustomize.py in the python library directory and add (as super user) the following lines
import site
site.addsitedir('/usr/local/lib/python2.7/site-packages')
in this file. It should solve the problem.

Related

Ways of installing python module

I'm new to python, about a month.
I know installing python modules can be done by using pip or easy_install. But when I was trying to install the regex module it gave me an error.
Typing pip install re in cmd gave me the following errors;
ERROR: Could not find a version that satisfies the requirement re (from versions: none)
ERROR: No matching distribution found for re
So I went to PyPI and downloaded a file there and now PyCharm doesn't give error when I import the module anymore.
So are there any difference between these ways of downloading Python modules or it doesn't matter ?
I'm using Windows 10 and have Python 3.8 and 3.8.1.
re is a built-in module, therefore you are not required to install this with pip.
Python Built-In Modules
re is part of the Python standard library so there is no need to install it separately. There are many ways to 'install' a package, e.g. using easy_install, pipx, venv, poetry, etc., but pip install --user is likely the way you're going to want to go to get started until you run into a compelling reason to explore other options. Either way, all these tools are essentially just various ways to move packages into PYTHONPATH, the place that Python looks for packages by default.

How do I add all include .h files in python directory

I am trying to install PyHook using PIP. When I run the command on cmd pip install pyhook3 I get a C1080 error that tells me there is no such .h file located in my directory. I traced the directory, downloaded the file and it showed me another. I kept doing this until I noticed that there seems to be no end. There seems to be a lot of missing .h files in this includes folder C:\Users\User\AppData\Local\Programs\Python\Python38-32\include directory. I don't want to have to download or copy and paste source code for each of these files. Is there any way to get all of them at once, or am I missing the plot entirely?
pyhook is a Python package with binary dependencies.
When running pip install pyhook3 you download the source and ask your computer to build it so it can be installed. It thus requires a compiler and a set of header files that are apparently missing for you.
A workaround may be to download manually a compiled version of this package and install it.
You can find on this page a set of binary wheel for pyhook (not pyhook3) for python3 (32 or 64 bit). Once you have downloaded the correct .whl, you can install it with pip install the_filename_you_have_downloaded.whl

Can't import ijson module on python 3.7.0

I have installed python 3.7.0 and my installation directory is AppData\Local\Programs\Python\Python37-32
Now I have tried to upgrade pip with:
python -m pip install –upgrade pip'
and I got:
Successfully installed pip-19.0.3
I did pip install ijson(while I was in folder AppData\Local\Programs\Python\Python37-32\Scripts) and double checked with the result being:
Requirement already satisfied: ijson in c:\users\myusername\appdata\local\programs\python\python37-32\lib\site-packages (2.3)
But when I go to my PyCharm project and I import ijson it can't find the module.Just to be clear if I import json or any other module I can work with it.
I know this has some duplicates and I have seen some of them. I have tried everything for example on these and others. Just for reference (possible duplicate)(possible dublicate 2)
but I haven't been able to solve my issue. Please tell me if I am missing something, maybe it is connected to the interpreter I am using or a wrong installion of python.
Thank you in advance
Make sure the python interpreter you are using in Pycharm is the one where you install ijson via pip.
You can do this by looking at the interpreter path in PyCharm, then opening that path in your terminal and trying import ijson
Also make sure the pip you are using is connected to the python interpreter you are using in PyCharm

Where did my python module install to?

I'm running python 3.6 via anaconda 3, using Visual Studio Code.
I followed instructions like these (Interactive Brokers API install) and downloaded the package to a local directory of mine say: c:\dev\pyib, so now the code is in c:\dev\pyib\IbPy-master
I open that directory in command line and run
python setup.py install
All runs ok.
But then my program, which is in c:\dev\pyib says Module not found. (In my case ibapi). The linter is also showing red.
There is no other python installed on this pc.
Where did the package install to? and how do I check that? What will I find where the package installed itself to that shows me its there?
Or do I have to use a trial-and-error with the linter and sys.path.append()? (I tried that with the directory where the files are downloaded to - to no avail)
I'm trying to set up the PYTHONPATH using the "env" in launch.json from Visual Studio Code, as shown in this unaccepted answer.
Current sys.path:
'c:\\dev\\pyIb',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\python36.zip',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\DLLs',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-
packages',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Babel-2.5.0-py3.6.egg',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin'
I deleted the ib directory and re-ran the install. The last line says: Writing C:\Users\user\AppData\Local\Continuum\anaconda3\Lib\site-pac‌​kages\IbPy2-0.8.0-py‌​3.6.egg-info So is the location of the egg-info the location of my undetected module? The actual folder in the site-packages is called ib.
Or could my problems be because of a difference in Lib vs. lib with the lowercase in the sys.path and the uppercase in the actual directory?
But the real question here is still: HOW DO I KNOW WHERE the package was installed what should I search for?
This answer is specific for anaconda3 Python and packages installed using python setup.py install (which is actually using distutils)
Take a look at anaconda3\Lib\site-packages you should see a directory for the package you installed.
The way to know for sure where your package is, is by doing a pip list then trying to pip uninstall and re-install again using the python setup.py install: Here are the detailed instructions:
When uninstalling, pip will tell you it cannot because it was done via distutils.
You'll get a message like this:
DEPRECATION: Uninstalling a distutils installed project (ibpy2) has been deprecated and will be removed in a future version.
This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
You'll be prompted to continue anyway. If you choose No, then you can find the directory in
C:\Users\<yourusername>\AppData\Local\Continuum\anaconda3\Lib\site-packages
Thanks to Emanuel Mtali for pointing me in the right direction
Some more information:
The problem I had was due to a stupid mistake of mine. I was running setup of a different (but related) package not used anymore. IbPy2 instead of TwsAPI. I was supposed to run the setup.py of the package installed via the latest version of the MSI from IB, and NOT the IbPy2 package. :-(

PyPi versioning

Newbie here. I've created my first Python package and I managed to register it on Pypi, as well as upload the tar.gz file. Now whenever I want to run:
pip install myPackage
I get this error in console:
Could not find a version that satisfies the requirement myPackage (from versions: 1.0dev)
No distributions matching the version for flashCardStudy
Storing debug log for failure in /Users/xxx/Library/Logs/pip.log
I believe this is because my version is development version I guess? So yeah, I can install it by adding --pre argument but what I'd really like is to turn it into a normal version so to speak.
I've tried figuring out how to do it and looking at some docs but I can't still figure it out. In my setup.py my version is set to '1.0' so I don't see where to problem is. If anyone wants to have a look at the file, here it is.
So I found the problem. I used utility called Paster which generates package structure, including setup.py and setup.cfg files among others. My utility hasn't been updated in a while and meanwhile submission rules to PyPi have changed. It now requires certain setup.py structure and unless it passes via pip, it's labeled as development version - which pip does not install without --pre argument.
So I just went to PyPi pages and looked at setup.py tutorial, did it their way and now it works.

Categories