"Python module not found" error on installed module - python

I am on Mac 10.6.8 with MAMP server installed.
I have installed both Scrapy and MySQLdb module under Python 2.6
When i import MySQLdb module from a python command line or in another project i see no error and it's working as expected. However when i import MySQLdb module in Scrapy project i get import error ("ImportError: No module named MySQLdb").
I am not a Python guru and such behavior is quite unexpected.
Why is that happening ? How this can be fixed ?
$ which python
/opt/local/bin/python (which is a symlink to "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6")
$ which scrapy
/usr/local/bin/scrapy

You have multiple Python instances installed (e.g., one is OS X built-in, another from MAMP). Check that those modules are actually installed in MAMP Python 2.6 (see what site-packages directory they reside in).
If you installed a module using easy_install from the built-in Python, you would not be able to use it from other Python instances.
P.S. Why use MAMP at all? Mac OS X already has all the components you need (Apache, MySQL, Python).

Related

Why is my python module not importing ON linux

As you can see I have imported the modules correctly using pip install. I googled a bit why the module was not imported and I realized I have to add it to PATH. I did that too but now there is a new error something about a syntax error
File "pygame/__init__.py",
self.reason = f"{exc_type.__name__}: {self.info}"
Is this because my chrome book can not run Pygame or is the problem something else?
Picture of my terminal with the error:
you need to run python3. to start python 3. Just running python starts python 2.7.
you have your installed packages in python 3.9 version while your python environment is 2.7, look for python3 executable and try with that version

Module importing works in python console (pycharm) but not works on terminal

Hi i'm recently working on a module in python (package named pykiwoom)
I installed a module in conda 32-bit environment pip install pykiwoom and tried to import this
from pykiwoom.kiwoom import Kiwoom
This works perfectly fine when I execute this in python console in pycharm
However, when I try this in terminal error occurs
ModuleNotFoundError: No module named 'pykiwoom.kiwoom'; 'pykiwoom' is not a package
internal structure of package pykiwoom looks like this
pykiwoom
init.py
kiwoom.py
parser.py
Can somebody tell me why this error occurs?
I think where you install your package is important in your case. You can check the packages installed using pip list in terminal, and check if you find it there.
This solution provides overview of how to setup your files as packages and modules.
Nevertheless, I think if you install your package in the terminal using pip, you could possibly access it.

Use of installed libraries

A Python script starts with:
from pathlib import Path
import sqlite3
which I read as an initialization of Libraries needed to run the rest of the script. However if the following error is returned in the terminal:
ImportError: No module named pathlib
I am uncertain how to interpret this. One assumption is that the pathlib library is uninstalled. However on the local system Python 2.7 and Python 3.4 are installed (I believe one was system pre-installed).
How can a library be asserted to exist? In case it is missing, how can it be installed?
You have to install it first
pip install pathlib
And with that your code should work.

How to import Python Libraries

I'm new to python and I'm using jython to create classes from python files.
I have jython and python both configured in my environment variables and when I type either in the command prompt I get their respective versions.
That's right I'm using windows :(
I need to create json output and was able to finally get the 'import json' to work and not give me an ImportError: No module name json.
Now I would like to import pysftp but I'm getting ImportError: No module named pysftp. Same thing with Paramiko import.
With that said I updated my jython to 2.7 and python version to 2.7.9 so I can use pip to import those libraries. Is this really what pip is for? How do I import library pysftp into my py file without it giving me the ImportError?
I'm a Java guy so I tried to locate pysftp jar and add it to the python Lib folder but that didn't work.
How do I import python libraries?

ubuntu - bz2 not available (/usr/bin/python older version, so am using /home/name/somedir for python

My server has python older version(2.6~), so I have created a separate dir for installing latest python. I have installed from binary .
Now, got error that 'bz2 module is not available'
got this problem when installing django-celery.
it is actually working from system level python like this:
/usr/bin/python:
python shell opens......
then, import bz2; works !!!
python (means, locally installed python, after source /venv/bin/activate)
in python shell, import bz2; says that it is not available. Can you please make it work for my local version( not global one).
Resources I found and tried from :
ImportError: No module named bz2 for Python 2.7.2
Python's bz2 module not compiled by default
A very similar question describes the same problem but for zlib. In short, you'll need libbz2.so and its headers in some location where Python can find them. You might need to download the bzip2 source code and compile/install that in your homedir as well.

Categories