I've tried to find answers like the ones here, but they don't work for me.
I have a python3.6 environment called py36. If I conda activate py36
and then run flask with
export FLASK_APP=main.py
flask run --port=5050
I get the following error:
Traceback (most recent call last):
File "/Users/USERNAME/anaconda/bin/flask", line 6, in <module>
sys.exit(flask.cli.main())
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/flask/cli.py", line 513, in main
cli.main(args=args, prog_name=name)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/flask/cli.py", line 380, in main
return AppGroup.main(self, *args, **kwargs)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/flask/cli.py", line 423, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/flask/cli.py", line 152, in __init__
self._load_unlocked()
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/flask/cli.py", line 176, in _load_unlocked
self._app = rv = self.loader()
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/flask/cli.py", line 237, in load_app
rv = locate_app(self.app_import_path)
File "/Users/USERNAME/anaconda/lib/python3.5/site-packages/flask/cli.py", line 90, in locate_app
__import__(module)
File "/Users/USERNAME/Documents/Google_Drive/Projects/project/main.py", line 3, in <module>
import MySQLdb
ImportError: No module named 'MySQLdb'
The issue isn't that there is no 'MySQLdb' installed, because it is installed under that environment.
if I do conda list
I get
mysql-connector-c 6.1.11 h42a37c1_0
mysqlclient 1.4.6 py36h0a44026_0
which confirms that mysql is installed on this environment.
and if I run python
I get
$ python
Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
which confirms that default python is 3.6.
As you can see everything is supposed to be python3.6, but the error comes from my python code for some reason launching python3.5 instead of python3.6. I don't have any prefixes or any headers telling which python it is supposed to run.
In fact this is the top of my main.py
from flask import Flask, request, render_template, jsonify
from flask_cors import CORS
from flask_pymongo import PyMongo
import MySQLdb
import json
import math
import pandas as pd
import numpy as np
from collections import OrderedDict
import pprint
import sys
app = Flask(__name__)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
In other words, my conda environment, which is supposed to safely contain a single python version (python 3.6), is failing to activate the correct python version inconsistently.
I'm scared to modify the paths but this is what I get if I echo $PATH
>>>echo $PATH
/Users/USERNAME/anaconda/envs/py36/bin:/usr/local/opt/openssl/bin:/usr/local/opt/openssl/bin:/usr/local/opt/openssl/bin:/usr/local/opt/openssl/bin:/usr/local/fsl/bin:/Users/USERNAME/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
The only way I fixed it is if I did the following:
conda activate /Users/USERNAME/anaconda
pip install pymysql
While this fixes my problem, it's a bandaid and it is not solving the issue. Because the base environment is not the one I want to be using when I conda activate py36
.
Any help would be deeply appreciated!
Thank you!