I installed python-magic (0.4.6) on my Win 7 64bit using pip.
I then installed cygwin 1.7.33-2 to provide the needed dlls and created a copy of cygmagic-1.dll named magic1.dll (see
When I run the Python 2.7.6 32bit shell, the "import magic" works fine.
However, a
magic.from_file('c:\user\username\sample.txt')
gives me a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\site-packages\magic.py", line 119, in from_file
m = _get_magic_type(mime)
File "c:\Python27\lib\site-packages\magic.py", line 107, in _get_magic_type
i = instances.__dict__[mime] = Magic(mime=mime)
File "c:\Python27\lib\site-packages\magic.py", line 55, in __init__
self.cookie = magic_open(flags)
WindowsError: exception: access violation writing 0x00000000
Any ideas what causes the this error and how I can fix it?
Thank you for your help!
The GnuWin32 file package has a 32-bit magic1.dll, along with its dependencies regex2.dll and zlib1.dll. I know from testing that this version works with python-magic. Here's an overview of the steps that I took to test this in 32-bit Python 3.3.
Extract the files to GnuWin32's installation directory:
C:\Temp>set "GNU=C:\Program Files (x86)\GNU"
C:\Temp>7z x -y -o"%GNU%" file-5.03-bin.zip > nul
C:\Temp>7z x -y -o"%GNU%" file-5.03-dep.zip > nul
Set up the environment to find the DLLs and magic file:
C:\Temp>set PATH=%PATH%;%GNU%\bin
C:\Temp>set MAGIC=%GNU%\share\misc\magic
Install python-magic:
C:\Temp>py -3.3-32 -m pip install python-magic
Collecting python-magic
Downloading python-magic-0.4.6.tar.gz
Installing collected packages: python-magic
Running setup.py install for python-magic
Successfully installed python-magic-0.4.6
Verify that it works:
C:\Temp>py -3.3-32
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:37:12)
[MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, magic
>>> magic.from_file(sys.executable)
b'PE32 executable for MS Windows (console) Intel 80386 32-bit'
Related
I am trying to install pyproj on a remote server running anaconda python 2.7.15 on Ubuntu 16.04. After running conda install -c conda-forge pyproj (first listed option at https://anaconda.org/conda-forge/pyproj), the package installs successfully (pyproj 2.0.2). However, upon running my program I get the following traceback:
Traceback (most recent call last):
File "run_qc_worker.py", line 1288, in <module>
GC.make_metadata_caches() # For percentiles check
File "/home/ubuntu/qc-mem/qc/lib/global_class.py", line 384, in make_metadata_caches
mercator_arr = self.proj_arr(lat_lon_arr) # project to x/y
File "/home/ubuntu/qc-mem/qc/lib/global_class.py", line 421, in proj_arr
inproj = Proj(init='epsg:4326') # WGS 84
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/pyproj/__init__.py", line 322, in __init__
self.crs = CRS.from_user_input(projparams if projparams is not None else kwargs)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/pyproj/crs.py", line 224, in from_user_input
return cls(**value)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/pyproj/crs.py", line 146, in __init__
super(CRS, self).__init__(projstring)
File "pyproj/_crs.pyx", line 307, in pyproj._crs._CRS.__init__
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/pyproj/datadir.py", line 62, in get_data_dir
"Valid PROJ.4 data directory not found."
pyproj.exceptions.DataDirError: Valid PROJ.4 data directory not found.Either set the path using the environmental variable PROJ_LIB or with `pyproj.datadir.set_data_dir`.
In my python script, I import with from pyproj import Proj, transform, and the relevant lines of code are:
inproj = Proj(init='epsg:4326') # WGS 84
outproj = Proj(init='epsg:3857') # WGS 84 / Pseudo-Mercator
Apparently, pyproj is unable to find a data directory. Searching the directory at
~/anaconda2/lib/python2.7/site-packages/pyproj, I confirmed there is no data directory. I have another server with an installation of pyproj on anaconda3 that does contain a data directory (with an epsg file). I copied this directory to the anaconda2 server, and declared the path using the environment variable as instructed in the traceback:
export PROJ_LIB=~/anaconda2/lib/python2.7/site-packages/pyproj/data
I still get the same error traceback.
I cannot find a data directory on the github repo for pyproj (https://github.com/pyproj4/pyproj/).
How can I resolve this error?
I was able to resolve this by installing a prior version of pyproj. I replaced the pyproj-2.0.2 installation with pyproj-1.9.6, by running conda install -c conda-forge/label/gcc7 pyproj. (proj4 was also downgraded from 6.0.0 to 5.2.0 as part of this install). This is the second available conda install option listed at https://anaconda.org/conda-forge/pyproj.
As described above, I also manually copied (scp) an existing data directory from an anaconda3 install on another server, and then exported the PROJ_LIB environment variable with the path to the data directory.
Note that when running pyproj-1.9.6 before exporting the path to data, the error traceback instead indicates RuntimeError: 'no arguments in initialization list'. This issue is well-described by other users here: https://github.com/pyproj4/pyproj/issues/134.
The current version of pyproj 2.2.0 works for me:
(base) $ conda create -c conda-forge -n proj27 python=2.7 pyproj
...
proj4 conda-forge/linux-64::proj4-6.1.0-he751ad9_2
pyproj conda-forge/linux-64::pyproj-2.2.0-py27hc44880f_0
...
(base) snowal#snowal-lx2:~$ conda activate proj27
(proj27) snowal#snowal-lx2:~$ python
Python 2.7.15 | packaged by conda-forge | (default, Feb 28 2019, 04:00:11)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyproj import Proj, transform
>>> inproj = Proj(init='epsg:4326') # WGS 84
>>> outproj = Proj(init='epsg:3857') # WGS 84 / Pseudo-Mercator
>>> import pyproj
>>> pyproj.__version__
'2.2.0'
Whenever I try to run python, I get this error relating to my path.
FrankieMacBook-Pro-2~$ python
Error processing line 2 of /Users/Frankie/Library/Python/2.7/lib/python/site-packages/homebrew.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1
import site; site.addsitedir("/usr/local/lib/python2.7/site-packages") mkdir -p /Users/Frankie/Library/Python/2.7/lib/python/site-packages
^
SyntaxError: invalid syntax
Remainder of file ignored
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
I've been using Python3 which doesn't have this issue for me, but now I have a task where I need to use Python2, so need to face this issue.
Any ideas what my issue is?
Did I somehow screw up my path with homebrew?
Your problem is that the Python interpreter runs site.py on startup. It is importing homebrew.pth and the copy of this file in your 2.7 installation is mangled.
Find this file and either delete it or use a text editor to take this code
mkdir -p /Users/Frankie/Library/Python/2.7/lib/python/site-packages
out of the line that begins
import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")
If you get further syntax errors after doing this, look at the ^ in the syntax error message. It will point to anything else the interpreter does not like.
I have VM win7 x64, Python 3.6 and Im trying to install pyrfc SAP connector.
I have installed NWRFC library, set it in PATH variable, installed egg pyrfc-1.9.5-py3.5 with easy_install, and installed Visual c++ redistributable 2015 (x64) 14. But import always fails:
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyrfc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrfc-1.9.5-py3.5-win-amd64.egg\pyrfc\__init__.py", line 22, in <module>
from pyrfc._pyrfc import get_nwrfclib_version, Connection, TypeDescription, FunctionDescription, Server
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrfc-1.9.5-py3.5-win-amd64.egg\pyrfc\_pyrfc.py", line 7, in <module>
__bootstrap__()
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrfc-1.9.5-py3.5-win-amd64.egg\pyrfc\_pyrfc.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python36\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
On same machine I have also Python2.7 - its using same NWRFC library and it works with no problem.
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyrfc
>>>
What could be the issue? Or how can I trace the import to know which other library is missing?
On github there are issues related to this, and some people solved it by:
One person reinstalled SAP SDK:
after some troubleshooting at least in my case was fixed after I re-downloaded the SAP SDK making sure I was downloading the Windows version.
Another person said:
If I uninstall pyrfc v2.0.1 and reinstall v1.9.93 using pyrfc-1.9.93-cp37-cp37m-win_amd64.whl, it works even without needing env var SAPNWRFC_HOME.
Try:
pip install pyrfc
It works for me.
As in the title, my system version is Ubuntu 10.04. The default version of Python is 2.6.5.
When I start python2.6 in command line and
import readline
This works well.
Then I compile the python 2.7.4 (Downloaded from www.python.org/getit). Nightmare began.
Here is how I installed Python 2.7.4:
./configure --prefix=/usr
make
su root
make install
Then tried import readline:
Python 2.7.4 (default, Apr 11 2013, 11:17:09)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named readline
Googled, firstly what I did is
sudo apt-get install libreadline5-dev
sudo ldconfig
Reinstall, does not work.
Then tried to install libpython and reinstall python 2.7.4, still does not work.
But the strange thing is that at the last few lines of command "make", the information is like this:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 bsddb185
bz2 dbm gdbm
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Seems there is no readline, but it just does not work!
BTW, here is another information might help:
/usr/bin/python -c "import readline; print readline.__doc__"
Importing this module enables command line editing using GNU readline.
Anyone can help me for this...
Thank you in advance.
I tried again, installed these packets:
sudo apt-get install build-essential
sudo apt-get install libreadline5-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Then remove everything about python2.7 including in /usr/local/bin, /usr/bin, etc and reinstall.
This time it works...
Ok...Hope this will help people who has the same problem with me.
I'm getting a psycopg2 error after updating to Mac OS X Mountain Lion, previously it was working fine.
This is the error if I try to import the module:
Python 2.7.3 (default, Sep 27 2012, 21:57:16)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.65))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _GSS_C_NT_HOSTBASED_SERVICE
Referenced from: /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psycopg2/_psycopg.so
I've used brew to install python and psycopg2.
Any idea would be helpful.
Thanks
Alex
Try brewing postgresql too. The error is probably in the way the libpq (the PostgreSQL client-side library, of which psycopg is a wrapper) is linked.
Mixing native and brew app is not that good... I would rather uninstall psycopg2 and python from brew and install the "Command Line Tools", like explained in pip install fails with /usr/bin/clang: No such file or directory. Then retry pip install, it will work, at least it did the job for me !