last day (14 days later) » 

11:33 AM
0
A: How to use virtual environment on downloaded code?

Mohammad AminThe error ImportError means you need to download some packages before you can run the code. You can install them globally in your system(which is not recommended) or you can use virtualenv. If you don't have pip, install it from here Then using pip you can install virtualenv, create a virtual...

 
So, if I download a project to the /Users/Bright/downloads/microblog-v3 folder, I should cd into it then run virtualenv env command?
 
Exactly. It creates the folder env in /Users/Bright/downloads/microblog-v3 and you're good to go.
 
I ran the env/bin/active command and it said -bash: env/bin/activate: Permission denied
 
did you run source env/bin/activate ?
 
OMG, I thought the source was file path
Now I tried it, I don't understand why it said no module named 'flask' after I've run pip install flask
 
11:33 AM
As I've said, if you want to install a package globally you should run sudo pip install Flask . It said no module named flask because flask was not installed.
 
Hi, thanks for opening the chat
 
Was your problem solved?
You're welcome
 
I tried with sudo, but it said requirement already satisfied
 
I guess you have two versions of python installed
open a terminal and type in python
in the terminal type "from flask import Flask"
 
have a look at the operations
(env) Brights-Mac-Air:microblog-v3 Bright$ sudo pip install flask
Password:
The directory '/Users/Bright/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/Bright/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
I do have 2 versions of python
 
11:37 AM
are you using virtualenv or not?
looks like you are, so you don't need sudo
 
I ran from flask import Flask, no errors
 
ok
is your virtualenv active
?
if it's active you'll see
(env) in your terminal
 
ok
how do you run the code?
 
python run.py
or python3 run.py
 
11:40 AM
python run.py
this gives you error ?
 
yes
the code is downloaded and unmodified, all I did was creating a virtual environment, and flask is installed both globally and in virtual environment, so it doesn't seem like the problem is in the code or operation
 
./run.py
try this, maybe this helps
 
hooray!
it worked
like magic!
 
there's something wrong with the virtualenv you've installed
with ./run.py you're using your global Flask installation.
I'm glad this helped you
 
so, does it still work if I quit the virtual environment?
since before it didn't
 
11:46 AM
yeah, I think it will
and if it works without the env, you can delete it
 
oh it didn't work
I just tried
 
then the env is just fine
 
oh and you said from flask import Flask didn't give any errors
 
11:48 AM
It was working then . I was wrong to think it was corrupt.
Good luck
 
Thank you for the help!
 

last day (14 days later) »