No module named weight_vector in sci with py2exe in windows - python

I get the following error message using Python v2.7.5 and scipy v0.12.0 with py2exe v0.6.9 on a 32 bit machine using 32 bit versions of the packages from Christoph Gohlke. If anyone can provide relevant and useful suggestions I would greatly appreciate it. Here is the error message:
Traceback (most recent call last):
File "MainWindow.py", line 13, in <module>
from svm.svm import SVM
File "svm\svm.pyc", line 4, in <module>
File "sklearn\svm\__init__.pyc", line 13, in <module>
File "sklearn\svm\classes.pyc", line 3, in <module>
File "sklearn\linear_model\__init__.pyc", line 20, in <module>
File "sklearn\linear_model\sgd_fast.pyc", line 12, in <module>
File "sklearn\linear_model\sgd_fast.pyc", line 10, in __load
File "weight_vector.pxd", line 14, in init sklearn.linear_model.sgd_fast
(sklearn\linear_model\sgd_fast.c:13206)
ImportError: No module named weight_vector
This is my setup.py file:
from distutils.core import setup
import py2exe
import sys
sys.path.append('../')
dcm = 'dcm.testDCM'
svm_path = 'svm.svm'
setup(windows=[{"script":"MainWindow.py"}],
options={"py2exe":{
"includes" : ["sip", dcm, svm_path,
'sklearn',
'scipy.sparse.csgraph._validation',
'sklearn.linear_model.sgd_fast.weight_vector']}})
Actually, I have solved the problem in this question scipy with py2exe problesm and solved it using the second answer in that question (the answer), adding the "scipy.sparse.csgraph._validation" in my includes options for the py2exe.
Then I want to do the similar thing for the error "No module named weight_vector", say, adding the "sklearn.linear_model.sgd_fast.weight_vector" in my includes options. However, it didn't work.
I check the directory "sklearn.linear_model.sgd_fast" only to find that the sgd_fast is a ".pyd" file rather than a .py file. Maybe this is why my methods cannot work.
I didn't get any idea about dealing with the pyd file. Have anybody met the similar problems or got any ideas? I really need your help.

Related

Python shell working differently on different location in the same machine inside same virtual environment

I have a cloud instance of a Linux machine (openSuSE) with multiple users.
I have created a virtual environment and installed all my required libraries (including Klein).
I have two users "a" and "b".
While logged in as "a" and inside virtualenv, when I open python shell at home directory and type
import klein
it imports normally.
Now when I change directory to
/home/b/
and run the same (open python shell, import klein) while being in the same virtualenv, it gives me an error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/a/.local/lib/python3.6/site-packages/klein/__init__.py", line 3, in <module>
from klein._plating import Plating
File "/home/a/.local/lib/python3.6/site-packages/klein/_plating.py", line 16, in <module>
from .app import _call
File "/home/a/.local/lib/python3.6/site-packages/klein/app.py", line 19, in <module>
from twisted.internet import endpoints, reactor
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/endpoints.py", line 58, in <module>
from twisted.protocols.tls import TLSMemoryBIOFactory
File "/home/a/.local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 63, in <module>
from twisted.internet._sslverify import _setAcceptableProtocols
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 158, in <module>
verifyHostname, VerificationError = _selectVerifyImplementation()
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 141, in _selectVerifyImplementation
from service_identity import VerificationError
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/__init__.py", line 7, in <module>
from . import cryptography, pyopenssl
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/cryptography.py", line 16, in <module>
from .exceptions import SubjectAltNameWarning
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/exceptions.py", line 21, in <module>
#attr.s
AttributeError: module 'attr' has no attribute 's'
Command "which python" gives same address at both location which is my virtualenv python address and that should be expected.
But what causes this weird python shell behavior.
Thank you
I solved it and a very shameful reason caused the error.
One of the modules Twisted uses is "attr" module. I had named one of my files attr.py and that is what was causing all the error.
I myself am not deleting this question if moderation has no problem, maybe somebody like me might be stuck at the same situation. It may help them.
Never name your python files same as that of any standard module unless overriding.
Also if your issue persists, then Jean's answer will definitely resolve it.
There can be multiple different Python packages that provide the same Python module. For example, there are at least two packages that provide the attr module:
https://pypi.org/project/attr/
https://pypi.org/project/attrs/
It's possible you've installed the wrong package based on the requirements. You can check what you have installed with pip freeze.

attempted relative import beyond top-level package message in PyCharm only

UPDATE: if I change the name of the select module (in which the import error occurs) to select1, the problem goes away! WHAT the?
First off: everything works fine when I try to import my package from the command line, or run pytest in the project directory.
But in PyCharm I'm getting the "attempted relative import beyond top-level package" problem when I try to run my tests, and ONLY while in PyCharm. I can't figure out why.
I have even deleted and re-cloned the repository and the problem still occurs.
Here is the link to the problem branch.
And here is the tb:
Testing started at 4:02 PM ...
C:\Users\ricky\AppData\Local\Programs\Python\Python37\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pycharm\_jb_pytest_runner.py" --path C:/Users/ricky/PycharmProjects/candejar/tests
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pycharm\_jb_pytest_runner.py", line 10, in <module>
from pkg_resources import iter_entry_points
File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources\__init__.py", line 36, in <module>
import email.parser
File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\email\utils.py", line 29, in <module>
import socket
File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\socket.py", line 52, in <module>
import os, sys, io, selectors
File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\selectors.py", line 12, in <module>
import select
File "C:\Users\ricky\PycharmProjects\candejar\candejar\select.py", line 24, in <module>
from . import exc
ImportError: attempted relative import with no known parent package
Process finished with exit code 1
I'm sure there is something simple going on here but I just can't figure it out. NOTE: I'm using Python 3.7 RC 1.
The sys.path in pycharm and the command line come out to be the same, except pycharm also includes the pycharm project main package directory (which for some reason appears twice).
I was able to solve this by deleting the .idea directory from the cloned repository and re-opening PyCharm. I still don't know what was wrong, but it is fixed now. Very weird.
UPDATE: it has something to do with the following line in the project .iml file in the .idea folder:
<sourceFolder url="file://$MODULE_DIR$/candejar" isTestSource="false" />
Removing that xml code solves the issue. But I do not know why, and I don't know how it got there in the first place (I do not recall messing around with any of my settings prior to this error).

Python error: No module named RuntimeError

Im trying to figured out this problem. Yesterday I installed PyScripter and since then, scripts doesnt work. When I run any script (in PyScripter or IDLE) and trying to "import arcpy", it gets this error:
import arcpy
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 14, in <module>
import arcgisscripting
File "C:\Python26\ArcGIS10.0\lib\arcgisscripting.py", line 81, in <module>
from RuntimeError import RuntimeError
ImportError: No module named RuntimeError
Have somebody any suggestion how to fix it?
Thanks to all very much!
Sounds like the module is not installed properly (or at all). To verify, do the following:
open a shell and start the python shell by typing python
(If this doesn't display an error, check that python is added to your system path or if it is even installed at all. But if you've used Python on said machine maybe system path issue)
enter the commmand help('modules')
review the list of modules that's returned to see whether arcpy is included
if not, then you may have to reinstall the module

Why am I getting this ImportError?

I have a tkinter app that I am compiling to an .exe via py2exe.
In the setup file, I have set it to include lxml, urllib, lxml.html, ast, and math.
When I run python setup.py py2exe in a CMD console, it compiles fine. I then go to the dist folder It has created, and run the .exe file.
When I run the .exe I get this popup window.
(source: gyazo.com)
I then procede to open the Trader.exe.log file, and the the contents say the following;
Traceback (most recent call last):
File "Trader.py", line 1, in <module>
File "lxml\html\__init__.pyc", line 42, in <module>
File "lxml\etree.pyc", line 12, in <module>
File "lxml\etree.pyc", line 10, in __load
File "lxml.etree.pyx", line 84, in init lxml.etree (src\lxml\lxml.etree.c:190292)
ImportError: cannot import name _elementpath
Included here is a copy of my setup.py file.
Please help me find the problem here. Thanks in advance.
Looks like py2exe doesn't realize it should include the lxml._elementpath module, which is conditionally imported by lxml.etree. You can tell it to include that module explicitly with the includes keyword argument in your setup.py.
setup(
options={'py2exe': {"includes": ["lxml._elementpath"]}}
)
Py2exe has made documentation of this error on this page: http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules
They also offer a working solution.

python 3.2: cx_freeze does not import all of pyserial

I am having issues building an exe verision of my python 3.2 script. The script requires pyserial and builds using cx_freeze. However, when I run the exe I get:
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27,
in <module>
exec(code, m.__dict__)
File "my_serial_program.py", line 1, in <module>
import serial
File "C:\Python32\lib\site-packages\serial\__init__.py", line 19, in <module>
from .serialwin32 import *
File "C:\Python32\lib\site-packages\serial\serialwin32.py", line 12, in <module>
from . import win32
ImportError: cannot import name win32
Doing a little snooping, Pyserial site-package has a "win32.py" module (in addition to serialwin32.py); however, in the compressed lib that cx_freeze produces, win32.py is missing. Simply placing a pyc version does not fix the issue. Also using cx_freeze "includes = [ ]" does not work.
Any ideas? Is my question even cogent (I am fairly new to python)?
I had the same issue. There is an option to include extra modules as mentioned in cx_Freeze ImportError: cannot import name and documentation for cx_Freeze
Just append --include-modules serial.win32

Categories