I meet a strange problem:
I have installed paste successfully. And "import paste" is ok.
But i noticed imp can not find it.
"imp.find_module('paste')" always gives "ImportError: No module named paste".
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import imp
>>> imp.find_module('paste')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named paste
>>> import paste
I have tested this on three different machines (Ubuntu14.04, Windows 10, Windows XP), all have similar problem.
I have duplicated this behavior. It seems a little odd to me. The docs describe some slight differences in find_module()'s behavior, but it doesn't seem to highlight anything matching this discrepancy. I suspect it's a bug or perhaps by design but not well documented.
The paste package in particular uses a pth configuration file. You can disable this behavior with -S to see its effect.
$ python -c 'import paste' && echo found
found
$ python -S -c 'import paste' && echo found
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named paste
The main problem seems that paste module doesnt have an __init__.py file
If you create it manually the problem is solved
Related
I use a Gentoo-based Docker image for CI with multiple versions of Python. Recently, I've started experiencing errors because one tool (coveralls) requires sqlite, which is missing. sqlite is part of the Python standard library.
This can be checked from the command line
>>> removing all .pyc files
>>> executing command
me#5b35f99c08af /source $ python
Python 3.6.9 (default, Dec 27 2019, 12:15:49)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sqlite3'
I couldn't find any notes in the Gentoo packaging database about this, but I'm not really familiar with it as an OS. I assume there must have been a problem building some relevant library.
Python has been installed like this:
RUN emerge -q -u dev-lang/python:3.6
But the error occurs for all the versions I'm currently testing with: >= 3.5. Any ideas as to what I'm doing wrong?
Pythonproject directory structure is like
--test
--upperlevel
-- __init__.py
-- manager.py
-- UpperLevel.py
this files in turn contains
# __init__.py
msg = "YAYY printing !!!"
print msg
# UpperLevel.py
from upperlevel import msg
# manager.py
import UpperLevel
So in my local MAC book with python 2.7.10, started a python shell in test directory.
From that shell,
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import upperlevel.manager
YAYY printing !!!
>>>
it worked !!!!
However i started a virtual machine (ubuntu 14.04 and python 2.7.10) with vagrant and added same test directory to it.
so if i did the same thing
Python 2.7.10 (default, Jul 13 2017, 19:26:24)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import upperlevel.manager
YAYY printing !!!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "upperlevel/manager.py", line 1, in <module>
import UpperLevel
File "upperlevel/UpperLevel.py", line 1, in <module>
from upperlevel import msg
File "upperlevel/upperlevel.py", line 1, in <module>
from upperlevel import msg
ImportError: cannot import name msg
>>>
So my questions are
1) why it is not working in the later case, i tried the same in docker and getting the same error
2) there is no such file in my project, File "upperlevel/upperlevel.py", line 1, in
3) why it is searching for upperlevel.py instead of UpperLevel.py
FYI
It looks like if we do "import upperlevel" from UpperLevel.py it is refering back to itself instead of going to upperlevel/init.py.
UPDATE:
I understood where the problem is from.... my test directory(volume) is being shared between mac and vagrant/docker, somehow UpperLevel.pyc is being treated as upperlevel.pyc in that shared volume.
Instead of running in a shared directory i created same folders/files in /home/vagrant and it worked.
It seems you are running from a Mac environment, and it is possible that the Python default search paths are different for those builds, despite the version being similar.
Try comparing:
import sys
print(sys.path)
It is probable that the default installation search paths might differ.
You can use the environment variable $PYTHONPATH to add additional import paths, while I don't really like this method it can be sufficient in most cases.
You can also setup your package in a proper module installation path.
Finally answering my own question...the problem is mac has a case insensitive file system and when it is mounted on linux, python is trying to use ubuntu mode of module reading like in the case sensitive way on a case insensitive File system.
After a lot of research found this link for docker https://github.com/docker/for-mac/issues/320 so those when using ubuntu docker with python on a mac be careful with your naming conventions.
I'm writing a script to redeploy code onto the intel edison through ansible. When running the following command I get an error. If possible I'd like to know how to find the file locally that causes this issue. I think that the file that throws the error on the server, "/home/root/.ansible/tmp/ansible-tmp-1444631867.66-245111051532005/setup", is probably generated from the files in the local repo.
However, I can't seem to find this setup file in ansible locally, and ansible removes this file from the server(edison) after the error gets thrown.
$ ansible-playbook -i inventory.yml provision_edison.yml
failed: [192.168.1.196] => {"failed": true, "parsed": false}
Traceback (most recent call last):
File "/home/root/.ansible/tmp/ansible-tmp-1444631867.66-245111051532005/setup", line 196, in <module>
import syslog
ImportError: No module named syslog
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
My inventory file inventory.yml
[edisons]
192.168.1.196
My provision_edison.yml file
---
- hosts: edisons
remote_user: root
tasks:
- name: "test if stuff is working"
shell: uname -a
I recoginise this as a python import error that is happening on the server. I tried seeing if the line number that the server threw, 196, corresponds to a file I have locally, but no luck.
root#edison-01:/usr/bin# ./python
Python 2.7.3 (default, Aug 15 2014, 22:34:09)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import syslog
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named syslog
A number of one-off Python builds don't include the syslog library, even though it's technically part of the core. This issue should be fixed in Ansible 2.0 by the following commit: https://github.com/ansible/ansible/commit/c57200925f7fc3c77da9a0b671ef7328cad15d8d
Something about your Python environment must be off. syslog has been a part of the standard library since at least 2.6. Is this a unix-based machine? Is this a clean installation of Python? I would check things like your Python path as well as see if you can import other standard libraries on that box.
i'm tying to play with sqlite3 on my centos server but it reports always the same error (module installed)....
Python 2.7.3 (default, Jun 29 2012, 19:03:18)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
on ubuntu and so on works fine.... any ideas of what i'm missing here?
i recompile the 2.7.3 again and it catch the sqlite3 libs well.
If you are under RHEL/centos 6, you can try this:
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/
This will work for CentOS:
ln -s /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/
/usr/local/lib/python2.7/ is already on python's path. No need to duplicate the file or add the python's path.
first find:
find / -name _sqlite3.so
/usr/usr/lib/python2.6/lib-dynload/_sqlite3.so
/usr/local/service/python2.7/lib/python2.7/lib-dynload/_sqlite3.so
/usr/lib64/python2.6/lib-dynload/_sqlite3.so
next
cp /usr/local/service/python2.7/lib/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/
this centso 6.5 python2.7.10
If you're using Python 2.7.3 on a Red Hat 5 or CentOS 5 machine, there was a bug that prevented the SQLite modules from compiling properly when building Python from source; you should see an error message when running make. It's since been fixed in 2.7.4 so your best option is to upgrade.
If that's not possible, then there's a patch available. Here's the bug page and the patch.
I'm trying to build python 2.5.2 on Solaris 8 using gcc 3.4.2. I can't see any immediate errors in the ./configure step but, once built and i enter the python shell doing an import time errors with :
Python 2.5.2 (r252:60911, Nov 21 2008, 18:45:42)
[GCC 3.4.2] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named time
What am i doing wrong? From what i can see with a cursory google is that there might be an error with libstdc++.so, but i can't find any hard details.
Any suggestions would be most welcome.
Many thanks,
Al.
The time module is not built by default in Python, if you build from a source distribution you need to explicitly enable all the modules you want to compile.
Open up Modules/Setup.dist in the python source tree and comment out the line which says:
#time timemodule.c
To enable the build of time module. Also remember that you need to recompile Python for this to take an effect.