Current versions of autopep8 and pep8 not compatible - pep8

I git cloned autopep8 (https://github.com/hhatto/autopep8/) but it depends on pep8 (https://github.com/jcrocholl/pep8) so I cloned that [pep8] too inside the autopep8 directory. Then I created a init.py with the contents "from pep8 import *" inside pep8 directory. Then I made sure I could import pep8 inside the autopep8 directory and that worked. However when I try to import autopep8 inside the autopep8 directory I get:
>>> import autopep8
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "autopep8.py", line 328, in <module>
del pep8._checks['logical_line'][pep8.continued_indentation]
AttributeError: 'module' object has no attribute '_checks'
Any solution to this?
EDIT:
I found the solution. The init.py also needs to be:
from pep8 import *
from pep8 import _checks

I was creating a python module out of pep8 and autopep8 in this example with a pep8 folder inside of an autopep8 folder, which in turn was inside of the root folder. I created __init__.py files in both pep8 and autopep8.
The contents were:
autopep8/__init__.py :
from autopep8 import *
pep8/__init__.py :
from pep8 import *
pep8/__init__.py had to be corrected to
from pep8 import *
from pep8 import _checks

Related

ModuleNotFoundError: No module named 'cleverhans.utils_keras' in Colab

I used the following to install cleverhans in Colab:
!pip install -qq -e git+http://github.com/tensorflow/cleverhans.git#egg=cleverhans
import sys
sys.path.append('/content/src/cleverhans')
import cleverhans
And it seems to work good. Then I use the following:
from cleverhans.utils_keras import KerasModelWrapper
wrap = KerasModelWrapper(network)
And I get:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-42-bf6d85d04ab3> in <module>()
----> 1 from cleverhans.utils_keras import KerasModelWrapper
2 wrap = KerasModelWrapper(network)
ModuleNotFoundError: No module named 'cleverhans.utils_keras'
Module cleverhans.utils_keras is a part of cleverhans_v3.1.0. The subdirectory has its own setup.py, i.e. it's its own separate package. Install it with the command
!pip install -U "git+https://github.com/cleverhans-lab/cleverhans.git#egg=cleverhans&subdirectory=cleverhans_v3.1.0"

sklearn: ImportError: DLL load failed: The specified module could not be found

Ive updated my Python version from 3.5.4 to 3.6.6 (in Anaconda 3) and now the line
from sklearn.metrics.pairwise import cosine_similarity
causes the following error:
Traceback (most recent call last):
File "<ipython-input-3-743ac88bcf9a>", line 1, in <module>
from sklearn.metrics.pairwise import cosine_similarity
File "F:\Program Files\lib\site-packages\sklearn\__init__.py", line 64, in <module>
from .base import clone
File "F:\Program Files\lib\site-packages\sklearn\base.py", line 13, in <module>
from .utils.fixes import signature
File "F:\Program Files\lib\site-packages\sklearn\utils\__init__.py", line 13, in <module>
from .validation import (as_float_array,
File "F:\Program Files\lib\site-packages\sklearn\utils\validation.py", line 22, in <module>
from ..utils.fixes import signature
File "F:\Program Files\lib\site-packages\sklearn\utils\fixes.py", line 83, in <module>
from scipy.special import boxcox # noqa
File "F:\Program Files\lib\site-packages\scipy\special\__init__.py", line 640, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
Im on Windows 7, 64-bit; previously the line worked fine, and other packages (Pandas, Numpy etc) still work, so it doesn't appear to be a PATH issue as some have suggested.
Ive seen numerous similar questions but all solutions have so far failed. E.g.
roll the installation back to Python 3.5.4,
uninstall & re-install Pandas, Numpy, Scipy and Sklearn, also update MKL/MKL-RT.
The changes suggested in Error when trying to import sklearn modules : ImportError: DLL load failed: The specified module could not be found
were already implemented
Does anyone have any further suggestions (specific to Anaconda etc)?
I solved it, and (in my case) the problem was scipy, not sklearn.
What i did was uninstall scipy with conda: conda remove --force scipy, and then install it with pip: pip install scipy. That worked for me.

numpy imported successfully on command line but not on IDLE

I can import numpy successfully using my python version 2.7.11 on the command line :
but not in IDLE where I get the following error :
Traceback (most recent call last):
File "/Users/macbookpro/Desktop/Python learning/Mortgages/mortgage_plot.py", line 2, in <module>
import pylab
File "/Users/macbookpro/Library/Python/2.7/lib/python/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/Users/macbookpro/Library/Python/2.7/lib/python/site-packages/matplotlib/__init__.py", line 124, in <module>
from . import cbook
File "/Users/macbookpro/Library/Python/2.7/lib/python/site-packages/matplotlib/cbook/__init__.py", line 35, in <module>
import numpy as np
ImportError: No module named numpy
What could be the source of this problem ?
A possible candidate for this error can be that the numpy package is not present in the directories where your IDLE searches for the package.
However the package is available for your command line python package path. Try adding the package location to your IDLE's package search path. I think that should resolve this error.
You can add following lines at top to add package path ( for this program only ) to use numpy :
import sys
sys.path
sys.path.append('path/to/package/numpy')
import numpy
Download numpy package from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy .
Or you can also work on anaconda

Version upgrade to scikit-learn

I wanted to do LDA on some data and so followed this example:
http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html#example-decomposition-plot-pca-vs-lda-py
however, on trying:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
I got an import error. Huh, maybe this is a new function, I thought. So I updated scikit-learn via conda from 0.15.2 to 0.17. But now I can't even import sklearn:
import sklearn
RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "//anaconda/lib/python2.7/site-packages/sklearn/base.py", line 9, in <module>
from scipy import sparse
File "//anaconda/lib/python2.7/site-packages/scipy/sparse/__init__.py", line 213, in <module>
from .csr import *
File "//anaconda/lib/python2.7/site-packages/scipy/sparse/csr.py", line 13, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: numpy.core.multiarray failed to import
I tried updating numpy and scipy using both pip and conda to no avail. I then tried a complete clean re-install of anaconda by:
rm -rf ~/anaconda
and a subsequent download of the .pkg from http://docs.continuum.io/anaconda/install#anaconda-install
Still I get the same error. Here are my OS and package details:
Mac OSX 10.5.2
bash-3.2$ conda -V
conda 3.18.6
scipy==0.16.0
numpy==1.9.1
scikit-learn==0.17
The last of these via pip freeze since I can't import it. I'm going nuts here. Any help much appreciated.
Try:
conda install numpy=1.10.1
I've had that module compiled against API version a but this version of numpy is 9 error before, and this solved it for me.

Python3.4.1 LINUX - from pip import main raises ImportError: Cannot import name 'main'

I'm using a server for which I am not root, and I have several scripts requiring Python 3.4.1. I built the software from the source tarball using the following syntax
$ ./configure --prefix=$HOME
$ make
$ make install
The software installed successfully, as I was able to launch python3 after modifying my .bash_profile to look in $HOME/bin. However, Pip was not so lucky.
$ pip3.4
Traceback (most recent call last):
File "/home/scnorton/bin/pip3.4", line 7, in <module>
from pip import main
ImportError: cannot import name 'main'
When I tried to run python3 get-pip.py, I get the following error:
Traceback (most recent call last):
File "get-pip.py", line 17474, in <module>
main()
File "get-pip.py", line 17466, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 17406, in bootstrap
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
I have checked the /usr/lib64 directory and concluded that zlib is installed on the server. I even executed the command module load zlib-1.2.8-1 and tried reinstalling pip again, with no luck. Could the problem be that Python3.4.1 is installed as a 32-bit application? If so, where can I go to get 64-bit Python3.4.1 for Linux?

Resources