There is a custom module "ETPython" generated by SWIG (consists of ETPython.py and binary _ETPython.so) and a simple script that invokes this module
sample.py
import ETPython
...
There aren't any problems if the script is run in an IDE (pycharm, internal python's IDLE, squish by froglogic so on). But if I'm trying to launch it in python shell in interactive mode or via terminal using
python3 sample.py
there is an error message like:
File "<path_to_file>/example.py", line 12, in <module>
import ETPython
File "<path_to_file>/ETPython.py", line 15, in <module>
import _ETPython
ImportError: dlopen(<path_to_file>/_ETPython.so, 2): Symbol not found: _NSLog
Referenced from: <path_to_file>/_ETPython.so
Expected in: flat namespace
Searching topics, I found that problem is related to wrong paths. So I added some code:
import os, sys
os.chdir("<path_to_dir>")
sys.path.append('<path_to_dir>')
os.system('export PYTHONPATH=<path_to_dir>:$PYTHONPATH')
This code helped to import the module in python shell in interactive mode but launching in terminal is still failing.
So the question is how to make it to work?
I found solution. The SWIG module was compiled incorrectly.
There was option for CMake that suppressed errors for undefined symbols
set(PLATFORM_LIBS "-undefined dynamic_lookup" )
That why the module doesn't contain NSLOG symbol.
The module was recompiled with additional
"-framework Foundation"
in swig_link_libraries statement. And now the module is imported correctly
I am trying to connect to the shopify api but am having difficulty connecting when using Eclipse+PyDev. When connection via python in a bash shell the same commands work OK
to install:
pip3 install --upgrade ShopifyAPI
shopify.py (my code)
import shopify
shop_url = "https://APIKEY:PASSWORD#mystore.myshopify.com/admin/products.json
shopify.ShopifyResource.set_site(shop_url)
The reference to shopify.ShopifyResouce.. throws the following in PyDev:
AttributeError: 'module' object has no attribute 'ShopifyResource'
I think it may be due to relative imports in the shopify module (the same code works fine in a terminal).
In shopify.py: (shopify API)
from shopify.resources import *
in shopify.resources: (shopify API)
from ..base import ShopifyResource
When I run
from shopify.base import ShopifyResource
ShopifyResource.set_site(shop_url)
I get ImportError: No module named 'shopify.base'; 'shopify' is not a package
Any ides how I can fix this?
The problem might be you created a shopify.py file in your IDE rename that file and that error will be solved
when I run mitmproxy command in command line, I get the following error.
% mitmproxy
Traceback (most recent call last):
File "/usr/local/bin/mitmproxy", line 7, in <module>
from libmproxy.main import mitmproxy
File "/usr/local/lib/python3.5/site-packages/libmproxy/main.py", line 5, in <module>
import thread
ImportError: No module named 'thread'
I googled this error and found this stackoverflow Q&A page.
pydev importerror: no module named thread, debugging no longer works after pydev upgrade
according to the page above, the error occurs because module "thread" is renamed to "_thread" in python3.
So, I know what's causing this error, but then what?
I don't know what to do now in order to get rid of this error.
I'm new to python. I've just installed Python and pip into my mac OSX as shown below because I want to use mitmproxy.
% which pip
/usr/local/bin/pip
% pip --version
pip 8.1.1 from /usr/local/lib/python3.5/site-packages (python 3.5)
% which python
/usr/bin/python
% which python3
/usr/local/bin/python3
% python --version
Python 2.7.10
% python3 --version
Python 3.5.1
could anyone please tell me what to do now?
Additional Info
As #linusg answered, I created "thread.py" file in "site-packages" directory and pasted the code below in "thread.py"
from _thread import *
__all__ = ("error", "LockType", "start_new_thread", "interrupt_main", "exit", "allocate_lock", "get_ident", "stack_size", "acquire", "release", "locked")
After I did this, "ImportError: No module named 'thread'" disappeared, but now I have another ImportError, which is "import Cookie ImportError: No module named 'Cookie'".
It seems that in Python 3, Cookie module is renamed to http.cookies (stackoverflow.com/questions/3522029/django-mod-python-error).
Now what am I supposed to do?
What I have in "site-packages" directory
% ls /usr/local/lib/python3.5/site-packages (git)-[master]
ConfigArgParse-0.10.0.dist-info/ mitmproxy-0.15.dist-info/
OpenSSL/ netlib/
PIL/ netlib-0.15.1.dist-info/
Pillow-3.0.0.dist-info/ passlib/
PyYAML-3.11.dist-info/ passlib-1.6.5.dist-info/
__pycache__/ pathtools/
_cffi_backend.cpython-35m-darwin.so* pathtools-0.1.2.dist-info/
_markerlib/ pip/
_watchdog_fsevents.cpython-35m-darwin.so* pip-8.1.1.dist-info/
argh/ pkg_resources/
argh-0.26.1.dist-info/ pyOpenSSL-0.15.1.dist-info/
backports/ pyasn1/
backports.ssl_match_hostname-3.5.0.1.dist-info/ pyasn1-0.1.9.dist-info/
blinker/ pycparser/
blinker-1.4.dist-info/ pycparser-2.14.dist-info/
certifi/ pyparsing-2.0.7.dist-info/
certifi-2016.2.28.dist-info/ pyparsing.py
cffi/ pyperclip/
cffi-1.6.0.dist-info/ pyperclip-1.5.27.dist-info/
click/ setuptools/
click-6.2.dist-info/ setuptools-19.4-py3.5.egg-info/
configargparse.py sitecustomize.py
construct/ six-1.10.0.dist-info/
construct-2.5.2.dist-info/ six.py
cryptography/ test/
cryptography-1.1.2.dist-info/ thread.py
easy_install.py tornado/
hpack/ tornado-4.3.dist-info/
hpack-2.0.1.dist-info/ urwid/
html2text/ urwid-1.3.1.dist-info/
html2text-2015.11.4.dist-info/ watchdog/
idna/ watchdog-0.8.3.dist-info/
idna-2.1.dist-info/ wheel/
libmproxy/ wheel-0.26.0-py3.5.egg-info/
lxml/ yaml/
lxml-3.4.4.dist-info/
In Python 3 instead of:
import thread
Do:
import _thread
You are trying to run Python 2 code on Python 3, which will not work.
As of April 2016, mitmproxy only supports Python 2.7. We're actively working to fix that in the next months, but for now you need to use Python 2 or the binaries provided at http://mitmproxy.org.
As of August 2016, the development version of mitmproxy now supports Python 3.5+. The next release (0.18) will be the first one including support for Python 3.5+.
As of January 2017, mitmproxy only supports Python 3.5+.
Go to you site-packages folder, create a file called thread.py and paste this code in it:
from _thread import *
__all__ = ("error", "LockType", "start_new_thread", "interrupt_main", "exit", "allocate_lock", "get_ident", "stack_size", "acquire", "release", "locked")
This creates an 'alias' for the module _thread called thread. While the _thread module is very small, you can use dir() for bigger modules:
# Examle for the Cookies module which was renamed to http.cookies:
# Cookies.py in site-packages
import http.cookies
__all__ = tuple(dir(http.cookies))
Hope this helps!
Easiest solution is to create a virtualenv with python2 and run mitmproxy on this virtualenv
virtualenv -p `which python2` .env
source .env/bin/activate
pip install mitmproxy
.env/bin/mitmproxy
The name of the file saved could be threading, this would give an error as threading is a predefined class in Python. Try changing the name of your file. It would help....
I am trying to run this python rewrite of Vlfeat library.
https://github.com/shackenberg/phow_caltech101.py. I am trying to run the application phow_caltech101.
This is throwing
File "/A/B/C/pyvlfeat-0.1.1a3/vlfeat/__init__.py", line 1, in <module>
import _vlfeat
ImportError: No module named _vlfeat
In the corresponding "init.py" file, I can see it is mentioned as "import _vlfeat". I am new to python, please let me know what is causing this error?
You need to download and install PyVlfeat module.
https://pypi.python.org/pypi/pyvlfeat/
As I see, pyvlfeat has some dependencies, so be sure to download these too:
Boost.Python (tested against version 1.35.0-5)
NumPy (tested against version 1.5.1)
Matplotlib (tested against version 0.99.3)
i have installed scrapy on my windows 7 machine in a virtualenv called scrapy.
scrapy startproject works and i made the tutorial from scrapy docs.
if i run
scrapy crawl dmoz
i get following error message:
File "C:\Users\mac\pystuff\scrapy\lib\site-packages\scrapy\utils\misc.py", line 42,in load_object
raise ImportError("Error loading object '%s': %s" % (path, e))
ImportError: Error loading object'scrapy.core.downloader.handlers.s3.S3DownloadHandler': DLL load failed: Could not find the specified module.
TESTS:
python console:
>>> import scrapy
>>> scrapy
>>> <module 'scrapy' from 'C:\Users\mac\pystuff\scrapy\lib\site-packages\scrapy\__init__.pyc'>
scrapy is available
powershell:
PS C: python -m pydoc scrapy.core.downloader.handlers
output:
NAME
scrapy.core.downloader.handlers - Download handlers for different schemes
FILE
c:\users\mac\pystuff\scrapy\lib\site- packages\scrapy\core\downloader\handlers\__init__.py
PACKAGE CONTENTS
file
ftp
http
http10
http11
s3
CLASSES
.
.
.
all other modules except s3 show the correct pydoc. for example:
python -m pydoc scrapy.core.downloader.handlers.file
only s3 gives the import error:
PS C: python -m pydoc scrapy.core.downloader.handlers.s3
PS C: python -m pydoc scrapy.core.downloader.handlers.s3.S3DownloadHandler
output:
problem in scrapy.core.downloader.handlers.s3 - <type 'exceptions.ImportError'>: DLL load failed: Could not find the specified module.
pywin32 was problem package. i ve tried to import it in python console and it could not be found. i copy these 3 packages from C:(yourpythonpath)\Lib\site-packages\pywin32_system32\ to C:(yourpythonpath)\Lib\site-packages\win32\
pythoncom27.dll
pythoncomloader27.dll
pywintype.dll
that solved the problem!
You can download it as an installation from here:
http://sourceforge.net/projects/pywin32/
I met the same problem and after a little bit research I tried almost all the suggestions and finally solve the problem. Here is my sequence:
Reinstall OPENSSL
Reinstall pywin32 amd64
Reinstall piwin32 32-bit
and magically the problem solved. My win server is 64-bit but the problem is solved by installing a 32-bit package. I guess this is because I previously install some other package that is 32-bit and didn't realize that. I'll keep you update if I have any progress.