Python error, Can't import from stdlib error - python

I'm getting at error when trying to import from qtgui site-package. Here's an excerp from the code that's having and error.
from gnuradio import qtgui
on of the files in sitepackage qtgui is textparser which contains the statement:
from stdlib import read_file
That's where the error is thrown.
Following the traceback the problem is that on of the files in qtgui, called textparser.py tries to import read_file from stdlib.
Here is the traceback of the offending line.
File "/usr/lib/python2.7/site-packages/qtgui/textparser.py", line 2, in <module>
from stdlib import read_file
ImportError: No module named stdlib
The line "from stdlib import read_file" looks correct except i cant find any information about a package called stdlib for python. However stdlib sounds like the c library. I'm new to Python, is that the proper way to import a c library?
So am I missing a python package or module, or a c library?
By the way I'm using python2.7, and Centos 7. I can't use Python 3 because I'm using GNUradio which i don't think supports Python 3.
Thanks in advance.

there is no such library in stdlib in python there is a library called stdlib_list what you gonna supposed to do in your code put a code sample

Related

should declare import fib.pyx or not?

in this example https://docs.databricks.com/user-guide/faq/cython.html
The author posted this code
import pyximport
import os
pyximport.install()
import fib
When I included the import my pyx module, it always complains
ImportError: No module named pyx_module
I looked at other sample code, like
https://www.4info.com/Blog/October-2014/Enhancing-Spark-with-IPython-Notebook-and-Cython
Spark with Cython
No one else shows this import statement. Should you be able to import the pyx module like this?
short answer is yes. you should call import pyx_module.
The reason I got confused is because I am using in a Spark code which uses zip files to pass dependencies, and the sc.addPyFiles call does not work with zip files, and import always fails.

Import pexpect in child module - 'no module named pexpect'

I'm seeing weird behavior that I don't understand, so I'm turning to the experts here on SO for help. I have looked at similar questions, without finding anything that looked helpful.
I'm writing a program that imports two custom modules.
If I run the main program using the cli "./ld_config_automation.py" I get the following error:
laptop$ ./ld_config_automation.py
Traceback (most recent call last):
File "./ld_config_automation.py", line 34, in <module>
from modules.networkcomponent import NetworkComponent
File "/path/to/pprograms/ssh_telnet_automation/modules/networkcomponent.py", line 7, in <module>
import pexpect
ImportError: No module named pexpect
However, if I run the main program using the cli "python ld_config_automation.py" everything works fine and the program runs.
My main program uses the following import statements.
import sys
import getopt
from modules.networkcomponent import NetworkComponent
from modules.recordclass import Record
The module I'm having trouble with "NetworkComponent" uses the following import statements:
import re
import pexpect
Also, if I remove import pexpect from the NetworkComponent module it works as expected without python in front (up to when it has to use pexpect. of course). So it doesn't seem to be a problem with importing modules, as re works ok, just not pexpect.
I'm developing this on mac os X but will implement on CentOS.

python - Import breaks, because library cannot import its own modules

I'm trying to use mongokit in my Pyramid project, but when I import it, I get the following error.
File "foo.py", line 5, in <module>
import mongokit
File "/home/.../mongokit/__init__.py", line 33, in <module>
from cursor import Cursor
ImportError: No module named 'cursor'
There is a cursor.py file with a Cursor class in it in the same folder as __init__.py.
According to the documentation, when you import a module, it is supposed to put its own directory at the beginning of the search path. However, when I print out sys.path from both foo.py and __init__.py, it is the same in both places.
I can't find anyone else having this problem.
Edit: I am using Python 3.3
mongokit is not compatible with python 3.
From their version notes:
v0.9.0
now MongoKit requires PyMongo >= 2.5
The same error may occur if you use python 3.x and try to import some module for python 2.x.

import error in python on ubuntu

I have created my first python module on ubuntu. When I'm trying to import the module in python using :
import brian
it is giving error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named brian
I have brian in /home/noamaan and python is in /usr/bin.
If you launch python from the directory that contains brian module, everything will work as it is now.
To import custom module from anywhere you want you should read attentively something on the import mechanism in python to learn where the imported modules are searched for, etc.
But to make your code work right now, I can recommend you the following:
Either extend your PYTHONPATH variable before running python, to include the directory of your module
Or append it right in the code by using sys module in this way.
import sys
sys.path.append("path/to/module/dir")
import brian
Also, see info on site module
by default Python import modules from Python path var.
You can view these paths so:
import sys
print sys.path

How/where does Python look for modules?

I am completely new to Python and wanted to use py2neo and tornado module.
In order to do that I ran setup.py for both modules and placed them into folders
C:\Python32\modules\py2neo
and
C:\Python32\modules\tornado
In the main program I guess these lines tell the interpreter where to look for files:
import sys
sys.path.append(r'C:\Python32\modules')
# Import Neo4j modules
from py2neo import neo4j, cypher
Reading the book I also added environmental variable (in Windows 7)
PYTHONPATH = C:\Python32\modules;C:\Python32\modules\tornado;C:\Python32\modules\py2neo
Edit
Now I figured out that Python Shell has to be restarted in order to load modified PYTHONPATH variable
In case the variable value is PYTHONPATH = C:\Python32\modules
and the program contains the line
from py2neo import neo4j, cypher
then the following lines are useless:
import sys
sys.path.append(r'C:\Python32\modules')
When I run the program however I get the following error:
Traceback (most recent call last):
File "C:\...\Python Projects\HelloPython\HelloPython\Hellopy2neo.py", line 15, in <module>
from py2neo import neo4j, cypher
File "C:\Python32\modules\py2neo\neo4j.py", line 38, in <module>
import rest, batch, cypher
ImportError: No module named rest
In the file neo4j.py there are the following lines:
try:
import json
except ImportError:
import simplejson as json
try:
from urllib.parse import quote
except ImportError:
from urllib import quote
try:
from . import rest, batch, cypher
except ImportError:
import rest, batch, cypher #line38
and rest.py file is located in folder C:\Python32\modules\py2neo so I don't know why I get the error
ImportError: No module named rest
Edit2:
Trying to import the py2neo directoy in Python Shell and list modules I get:
>>> import py2neo
>>> [name for name in dir(py2neo) if name[0] != '_']
['rest']
I guess there are some unneccesary imports as well and would be very thankful if anyone explained, which imports should be added and excluded (in PYTHONPATH and scripts) in order the program to run without errors.
I suspect the problem is that the import syntax for relative imports has changed in transition from Python 2 to Python 3:
The only acceptable syntax for relative imports is from .[module]
import name. All import forms not starting with . are interpreted as
absolute imports.
The modules you installed use the syntax that would work in Python 2. You could either install them for Python 2, or look for a version of py2neo that supports Python 3, or try to port it manually (the import line should look like from . import rest, but you'll probably face other problems later) or with 2to3 tool.
Update: I tried installing py2neo with pip. It failed for Python3 and finished successfully for Python 2. The version is 1.2.14.

Categories

Resources