python 2.7 will not import despite adding to path - python

Riddle me this..
importing package disaster..why?
contents of yenlib:
/var/yenlib
- __init__.py
- yenlib
- __init__.py
- json_.py
import sys
sys.path.append('/var/yenlib')
sys.path.append('/var/yenlib/yenlib')
from yenlib import json_ as json
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name json_

Skip the second "append" statement and import from yenlib.yenlib
import sys
sys.path.append("/var/yenlib")
from yenlib.yenlib import json_ as json

Related

I need help using ctypes on jython

I want to use libxmp.
I used:
import sys
sys.path.append('/usr/local/lib/python3.8/dist-packages')
which directly locate to libxmp
from libxmp import XMPFiles, consts
from libxmp.utils import file_to_dict
upper code box is the import part
I faced this problem:
Traceback (most recent call last):
File "/home/webprime/jython/jython/jython.py", line 5, in <module>
from libxmp import XMPFiles, consts
File "/usr/local/lib/python3.8/dist-packages/libxmp/__init__.py", line 37, in <module>
from ctypes import util
ImportError: cannot import name util
it works on Python 3.

How to specify the process in python pwntools?

Cant set the process in Python 2.7.17 pwntools.
Source code:
from pwn import *
s=process('/root/Dokumente/Scripts/example_program')
I tried from pwn import *:
root#bitpc:~# python pwn.py
Traceback (most recent call last):
File "pwn.py", line 1, in <module>
from pwn import *
File "/root/pwn.py", line 2, in <module>
s=process('/root/Dokumente/Scripts/example_program')
NameError: name 'process' is not defined
That was not working. Then i imported process directly:
root#bitpc:~# python pwn.py
Traceback (most recent call last):
File "pwn.py", line 1, in <module>
from pwn import process
File "/root/pwn.py", line 1, in <module>
from pwn import process
ImportError: cannot import name process
I got an import error. How to fix this?
It seems that your exploit script's name is pwn.py. rename it to some other name such as exp.py. otherwise python will try to import things in your pwn.py instead of importing things from pwntools.

How to import a file in the same folder in python?

My directory structure is as follows;
ATGWS
|-models
|-SiteConfig.py
|-__init__.py
|-atgws.py
|-CustomEncoder.py
|-__init__.py
I want to call customencoder.py within atgws.py.
i try like this;
from CustomEncoder import CustomEncoder
..
app.json_encoder = CustomEncoder
but not working.
I get
Traceback (most recent call last):
File "/Users/ratha/projects/test711/ATGWS/atgws.py", line 3, in <module>
from CustomEncoder import CustomEncoder
ImportError: cannot import name CustomEncoder
How can i call this?
I fixed it like
from CustomEncoder import CustomEncoder
..
app.json_encoder = CustomJSONEncoder()
Works.

Unbable to import function

I have tried following
when I tried to import the class from the file named plyparser.py of pycparser(https://github.com/eliben/pycparser/blob/master/pycparser/plyparser.py)
using the following statement
from pycparser.plyparser import Coord
But, I am unable to import function parameterized from plyparser of pycparser using the following statement
from pycparser.plyparser import parameterized
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name parameterized
How to resolve this issue.

ImportError: cannot import name

For some reason I receive an ImportError every time I try to import a class from another file. Here's the github page for my project: https://github.com/wheelebin/mcnextbot
Here's the error that I'm receiving:
Traceback (most recent call last):
File "ircbot.py", line 36, in <module>
from test import mcnextlvl
ImportError: cannot import name mcnextlvl
Here your from test import something refers to the module test in <PYTHONPATH>/lib, not yourselves test.py, and there is no submodule/class mcnextlvl there. You should use from lib.test import mcnextlvl as #sgmart commented.
The __init__.py python file allow you can import your individual modules named 'test' from the lib package.

Categories