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
Related
I have begun learning to program (in general, and in Python), and I am trying to import a module. I have installed it (using pip install --user requests) and the folder appears in my file explorer. When I try to import requests now inside IDLE, I get a ModuleNotFoundError.
I have tried adding the folder to the PATH environment variable, although I am not sure I understand what this means, but it did not work. What can I do?
If "pip freeze" lists the module, then one option will be to close the idle and type the following at the command prompt/terminal.
python -m idlelib
New IDLE will start and it should be possible to import the module.
That means that the installation you made was not done properly, so when you type in requests to get the module in your script it cannot find it.
Just reinstall it properly with (if the prompt for the python version you want to use is simply python):
python -m pip install requests
EDIT:
Adding to this, based on the comment of #AST :
Indeed, if you get Requirement already satisfied when using the above command, you can first delete requests with the following command, and then try the installation command.
pip uninstall requests
I try a python code for signature recognition, and there is an import ffnet module (from ffnet import mlgraph, ffnet), but I got an error when I run it.
The error is:
ModuleNotFoundError: No module named 'ffnet'
I have install the module, but still got that error
Help me to fix this :)
You need to make sure that it is correctly installed. The error message means directly "You haven't installed it properly".
Depending on what Python version you're using, you should have a package manager called pip that takes charge of installing and uninstalling modules. Try:
pip2 install ffnet if you have Python 2.
pip3 install ffnet if you have Python 3.
Alternatively, you may have installed Python using Anaconda. In this case, use conda install ffnet. In all cases, run the proposed commands in a terminal.
However, it would be quite useful to have more details about your problem (what OS do you have, how and where did you install Python, what version do you have).
There is great chance that the pip (i suppose you use pip for installation, the idea is identical) you use to install ffnet is not correspond to the python you are using. Maybe a virtualenv is running, or you using python 2 but ffnet is installed with pip3
My suggestion:
- Run which pip. Run which python. Compare the results if anything seem wrong (python2 pip3 for example). Try to run python2 and pip2 instead of python and pip
- If the above suggestion doesn't work, you should try to recheck your PATH: Find the pip correspond to your current python (usually within the same dir) and export PATH=/path/to/THAT/pip/:$PATH
- If the problem still persist, I suppose your pip file's first line (for specifying its corresponding python path) has been modified without your awareness. You will have to manually edit it to something like #!/usr/bin/python3
Hope this help!
When I try to do python manage.py syncdb in my Django app, I get the error ImportError: No module named azure.storage.blob. But thing is, the following packages are installed if one does pip freeze:
azure-common==1.0.0
azure-mgmt==0.20.1
azure-mgmt-common==0.20.0
azure-mgmt-compute==0.20.0
azure-mgmt-network==0.20.1
azure-mgmt-nspkg==1.0.0
azure-mgmt-resource==0.20.1
azure-mgmt-storage==0.20.0
azure-nspkg==1.0.0
azure-servicebus==0.20.1
azure-servicemanagement-legacy==0.20.1
azure-storage==0.20.3
Clearly azure-storage is installed, as is evident. Why is azure.storage.blob not available for import? I even went into my .virtualenvs directory, and got in all the way to azure.storage.blob (i.e. ~/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/azure/storage/blob$). It exists!
What do I do? This answer here has not helped: Install Azure Python api on linux: importError: No module named storage.blob
Note: please ask for more information in case you need it
I had a similar issue. To alleviate that, I followed this discussion here: https://github.com/Azure/azure-storage-python/issues/51#issuecomment-148151993
Basically, try pip install azure==0.11.1 before trying syncdb, and I'm confident it will work for you!
There is a thread similar with yours, please check my answer for the thread Unable to use azure SDK in Python.
Based on my experience, Python imports the third-party library packages from some library paths that you can check them thru codes import sys & sys.path in the python interpreter. So you can try to dynamically add the new path contains the installed azure packages into the sys.path in the Python runtime to solve the issue. For adding the new library path, you just code sys.path.append('<the new paths you want to add>') at the front of the code like import azure.
If the way has not helped, I suggest you can try to reinstall Python environment. On Ubuntu, you can use the command sudo apt-get remove python python-pip & sudo apt-get install python python-pip to reinstall Python 2.7 & pip 2.7.(Note: The current major Linux distributions use Python 2.7 as the system default version.)
If Python 3.4 as your runtime for Django, the apt package names for Ubuntu are python3 and python3-pip, and you can use sudo pip3 install azure for Python 3.4 on Ubuntu.
Any concern, please feel free to let me know.
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.
Can you delete python modules? I've installed one that I would like to remove, and can't seem to figure out how.
Thanks
To find where the module is, just do a:
$ python
>> import module
>> print module.__file__
'/some/directory'
or if it is a package:
>> import package
>> print package.__path__
and delete it.
If you are using python under windows, the following command is what you need
pip uninstall module
In some cases, you may have installed different versions of the module. For example, after I had the lxml3.4.4 installed via pip, I also installed lxml3.5.0 using its pre-built binary, and thus, the command listed above only remove the first one. So I need to run it twices
pip uninstall lxml
pip uninstall lxml
And it got completed uninstalled. See whether it helps.
This has already been asked here.
Go into the "site-packages" directory of your python install and remove the files manually.
Another way using -m flag (especially if Alex Feng's answer is not working) is:
python -m pip uninstall module
NOTE: This works only for Windows, and is to be run in the Command Prompt.
To see if the module has been uninstalled, simply try to import the module again.