2

When I create an anaconda virtualenv and install things with pip inside of it, it seems to run into errors which might indicate that its using python 2?

conda create -n tensorflow-3.5 python=3.5 ipykernel
source activate tensorflow-3.5
pip install matplotlib
(tensorflow-3.5) devs-MacBook-Pro:Documents conduce-laptop$ python
Python 3.5.3 |Continuum Analytics, Inc.| (default, Mar  6 2017, 12:15:08) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/conduce-laptop/anaconda2/envs/tensorflow-3.5/lib/python3.5/site-packages/matplotlib/__init__.py", line 115, in <module>
    import tempfile
  File "/Users/conduce-laptop/anaconda2/envs/tensorflow-3.5/lib/python3.5/tempfile.py", line 45, in <module>
    from random import Random as _Random
ImportError: bad magic number in 'random': b'\x03\xf3\r\n'

Why is this happening? How should I install modules instead? Do I need to use pip3 instead?

BigBoy1337
  • 4,735
  • 16
  • 70
  • 138
  • 4
    Do you have any `*.pyc` files or `__pycache__` directories lying around? Remove those. –  May 16 '17 at 21:33
  • @Evert from which directory should I remove *.pyc files? – BigBoy1337 May 16 '17 at 21:34
  • I'm not convinced that this is a duplicate of [this question](http://stackoverflow.com/questions/514371/whats-the-bad-magic-number-error) as the solution on how to handle this error within virtualenv is not obvious, or is it? Should we reopen the question? – ImportanceOfBeingErnest May 16 '17 at 21:52
  • 1
    @ImportanceOfBeingErnest and everyone else interested, I did solve the problem with this line: find . -name '*.pyc' -delete shown in the other question – BigBoy1337 May 16 '17 at 21:57
  • Ok, then it really is as simple as that and we keep it closed. – ImportanceOfBeingErnest May 16 '17 at 21:58
  • Goto your home directory. And, then, "sudo find . -name "*.pyc" -exec rm -f {} \;" – bruce Oct 24 '18 at 06:37

0 Answers0