Forums

Able to access Module from Bash by not inside Flask

Hello,

I have install PyWit in my Virtual Env. I am able to access it from all my directories, including mysite. But if I try to import wit anywhere inside my flask apps, its giving error saying "ImportError: No module named 'wit'".

Kindly help.

I could solve the problem by deleting the installation, and pip installing again in virtualenv.

Thanks.

update1: Now I could access the module from mysite, by directly executing the file. But not accessible from flask_app I get the same error, if I import the file (which I could execute) in flask_app I still get the same error.

update2: While I was running bash, (default bash seems to run Python 2.7) I found I could not import. If I run Python3.4 in bash, I am able to import wit. My flask was set up for 3.4, yet it doesn't seem to see wit module!

What was the command you used to install PyWit? If it was pip3.4 install --user and you were outside your virtualenv when you ran it, then that would give exactly the effects you're seeing.

If not, can I take a look at your files? We can see them from our side, but we always ask for permission first.

Yes, I used pip3.4 install --user and I am able to access from bash python 3.4 but not with bash python 2.7 default. Kindly look into my files and tell me what should be changed. I want to be able to import wit, from inside my flask app.

You can check my flask_app, line no. 245, I have commented it. I want to be able to import wit at that line. The same import wit is working in bash, in the directory where flask_app is located.

Thanks.

update: after I installed pip2.7 install --user pywit, I am able to import wit, in all the bashes. but the same is not working in flask_app.

Problem rectified. Thanks.

If you're using a virtualenv, you shouldn't use the --user flag. You only need that to install stuff if you're not using a virtualenv.

Previously when I was installing in virtualenv, I did try to use pip without --user, but I got a error that I didn't have permission to create directory.

That would suggest that you weren't really in the virtualenv. Normally if you're in the virtualenv your bash prompt will change to show its name.

I guess you are right. I opened bash from virtualenv, but I am not sure. I was probably not in virtualenv. Thanks.

Let us know if you get errors again and, on checking, you're sure you're in the virtualenv -- it shouldn't happen, and I haven't heard of it happening before, but it's possible there's a bug somewhere.

In case if I experience this again, I will post it here. Thanks for your support.