I created a Python module and installed it using pip3. If i check on dist-package folder its there. If i import this module into a new Python project its ok.
Problem: I would like to use this module on my Django project, but when i try to import it can't be found.
Already tried: If i copy the module to site-package, it works but i don't get why i have to do this. I would like that this Python module installed with pip3 is visible for everyone without the need to copy/paste from dist folder.
Whatever the package you installed using pip3, those packages mapped to python3 version, and also will be installed in /usr/lib/python3.x/site-packages/
for your reference, What's the difference between dist-packages and site-packages?
Related
I'm running macOS version 11.0.1.
I'm trying to import a module called troposphere
I have Python2.7 as well as Python3.9.1 installed
When I try to import troposphere using Python2.7 like
#!/usr/bin/python
from troposphere import Template
It does work. But when I try to import the same using Python3.9.1 like
#!/usr/bin/python3
from troposphere import Template
It throws error like this
ModuleNotFoundError: No module named 'troposphere'
What should I do? Please help
it is because the python interpreter you use to run your code doesn't have troposphere installed.
Managing multiple Python version on the same computer is tricky, But I will try to explain it.
I assume that you are using python your_script.py to run your code, and pip install troposphere to install package right? But think of this, how does your system know exactly which python you are running and which python to install package? Here's how to check the full path of your python command and pip command.
type python command enter python console
then type this:
import sys
print(sys.executable)
3. navigate up and down little bit, you will find a bin folder include bin/python which is your interpreter and bin/pip which is your pip command. And there's a lib/site-packages folder, this is where third party library been installed to.
4. if you see import error, use the above method to locate the python interpreter and check the site-packages folder, most likely there's no such troposphere folder in it. Then you need to use the full path of the <path-to>/bin/pip to install troposphere. Then your problem is solved.
If you are using home brew or the python installer download from www.python.org, your system probablly already messed up. The recommended way to manage multiple Python version is to use pyenv https://github.com/pyenv/pyenv. It allows you to install any python version and easy to delete them.
Chek if the module was depreciated
I am on Windows 7 with Python 3.5 installed on it.
Below is what happens:
import pip # works as expected
import pip3 # results in below error
ImportError: No module named 'pip3'
I have pip and pip3.exe both sitting in the same scripts folder.
I have scripts folder, site packages and python folder all added to my environment variable path (I have added it in user profile, as I do not have admin access to add to system variables)
Is there any solution which you all have tried and worked. I am new to python and any help is appreciated.
So, I learned that my problem with installing beautifulsoup was because of the firewall restriction in my organization, which I was relating to pip install.
I learned of the proxy settings and using that, got to install bs4 via the conda interpreter.
Thank you for all the answers, which made me think through on various aspects, which I would not have thought of without the probing questions brought up here.
I have already installed my wanted module from pip by using pip install but when i open up a program in idle and put import menu it says module not found what did i do wrong, im using python 3.7 and have the latest version of pip.
Python looks for its modules and packages in $PYTHONPATH. You'll need to figure out if the __init__.py module of the package you'd like to use is in python's path. To find out whether it is in python's path, run:
import sys
print(sys.path)
within python.
To add the path to your module, run:
sys.path.append("/path/to/your/package_or_module")
and you should be set.
I met the same problem, but in my case the package is created by myself. So this answer applyes to the custom packages. See Why customer python package can not be imported? for details.
Just in case someone is meeting a similar problem to mine.
Pay attention to the case of the package. In my case, the package is called 'shapely'. And I installed it through
pip install Shapely
But you have to import as
import shapely
I am using vagrant to run my python environment. In my data models I am using django-picklefield module.
when I run my server it says
ImportError: No module named picklefield.fields.
I tried to uninstall and install the picklefield module. Still having the same problem.
You should be able install via:
/[your python install directory]/bin/pip install django-picklefield
If you do this directly instead of a general pip call to install django-picklefield, that will ensure that it is installed on the correct version of Python.
Based on your description my best guess is that you have multiple versions of Python installed, and that your install/uninstall is happening on the wrong one.
I'm following the tutorial "Think Python" and I'm supposed to install the package called swampy. I'm running python 2.7.3 although I also have python 3 installed. I extracted the package and placed it in site-packages:
C:\Python27\Lib\site-packages\swampy-2.1.1
C:\Python31\Lib\site-packages\swampy-2.1.1
But when i try to import a module from it within python:
import swampy.TurtleWorld
I just get no module named swampy.TurtleWorld.
I'd really appreciate it if someone could help me out, here's a link to the lesson if that helps:
http://www.greenteapress.com/thinkpython/html/thinkpython005.html
If anyone else is having trouble with this on Windows, I just added my sites-package directory to my PATH variable and it worked like any normal module import.
C:\Python34\Lib\site-packages
Hope it helps.
I extracted the package and placed it in site-packages:
No, that's the wrong way of "installing" a package. Python packages come with a setup.py script that should be used to install them. Simply do:
python setup.py install
And the module will be installed correctly in the site-packages of the python interpreter you are using. If you want to install it for a specific python version use python2/python3 instead of python.