I have created a virtual environment on which I ran the following command to install Zeep (I am on macOS Big Sur):
pip3 install zeep
To verify if I have correctly installed it I ran:
pip3 freeze
And I can see in the list :
zeep==4.0.0
However, when I run my script using flask run I get the following error:
I have flask installed and activated my virtualenv:
What I don't understand is that when I go directly on python from the command line it does import zeep :
Any help would be appreciated. Thank you.
Two things come to my mind with this problem.
Make sure the venv is activated
source /venv/bin/activate
Make sure flask is installed after activating the venv.
pip install Flask
You are running in an Anaconda/Conda virtual environment, this can be seen from your command prompt. Conda is a package management platform like, but separate to, Pip.
When you install a package with Pip it is not available in an Anaconda virtual environment.
Also you need to take note of where you are actually installing packages to when you run pip. If you run pip outside of a virtual environment then it is going to install packages into your system Python which is not a good thing.
I have flask installed and activated my virtualenv:
How are you activating the virtual environment? Your third screenshot shows the Anaconda installation of Python.
Related
I try using pip and pip3 and python -m pip and all ways to install. The terminal says the packages already installed after the first try to install, but when I try to import the package I had error no moudel name.
I feel the peoblem coming form here
But I am not sure
And when I go to packages in pycharm I saw the packages not installed
I appreciate your help
I'm assuming you're using windows.
It looks like you install the package directly in your system and PyCharm are using a virtual environment to run your code.
Try to activate this virtual environment before run your code:
source venv\Scripts\activate
If you see "(venv)" at the begging of your terminal prompt the virtual environment are activated.
Run pip list to check what packages are installed in there and probably you have to install your package another time, this time in your activated virtual environment. The official documentation will help to understand how and why use virtual environments.
After that you can try to run your code directly from the terminal:
python your_file.py
Install the packages from PyCharm itself, not the terminal as I think pycharm is running a virtual environment.
Maybe you can follow https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#packages-tool-window
Hope everyone is doing fine :)
I'm new to python, so I'm having trouble cause I've installed anaconda (for machine learning) and now, my local projects in VS Code with python, don't find modules installed from pip install.
I've searched online and I guess it has something to do with the path... Here's the path when I install the module:
user_stuff.../opt/anaconda3/lib/python3.9/site-packages
I want to install modules into my project on desktop, here's the path:
user_stuff.../Desktop/python-project
I keep getting this error when trying to import:
ModuleNotFoundError: No module named 'qrcode'
How do I change this? It's really frustrating :(
I guess your pip is referring to the pip provided by the system, it should be now referring to the pip provided by anaconda.
$ which pip
$ alias pip="/Users/my-username/anaconda3/bin/pip"
$ pip install qrcode
Do you use jupyter notebook in vs code? I prefer it because there you can easily select the environment you are using. And if you want to pip install anything in a environment you have to first activate it in the console with conda activate env name
I am using python 3.9.2 and pip 21.0.1. I've created a virtual environment. In that I installed flask 1.1.2 and Werkzeug 1.0.0.
I tried to install coolname==1.1.0 and wtforms_components==0.10.5, it says successfully installed but it is not importing files.
from coolname I want generate_slug package
and from wtforms_components, I want TimeField
What I have done to install them:
pip install WTForms-Components==0.10.5
pip install coolname
Can you please tell me how can I get these packages?
You might be using the global interpreter instead of your virtual environment.
You need to check that your IDE's interpreter is configured to that virtual environment you created. if you want to run it from the command line you first need to activate it with env_name\Scripts\activate and then run it.
I am new to Python. Today I installed flask in C:Users\myName\FolderA using below commands and it worked fine. But when i try to create a structure C:Users\myName\FolderA\FolderB and create app.py in it, my VSCode says "ModuleNotFoundError: No module named 'flask'". Does this mean i need to install flask in Folder B too? Is there a way to install flask globally and make all folders under 'FolderA' access the libs?
Commands used to install Flask
C:Users\myName\FolderA\py -m venv env
C:Users\myName\FolderA\env\Scripts\activate
(env)c:Users\myName\FolderA\pip install flask
You are using a virtualenv. Everything installed inside a virtualenv resides inside that virtualenv (which is nice in fact: all your dependencies for that project only!).
If you want to install packages globally, run
pip install flask
without having run the activate script first (that activates your virtualenv).
PIP should install packages globally. You shouldn't have to reinstall flask everytime. Seems like something is wrong with your PIP. How did you install Python?
You could try updating PIP, which could fix it. Try running
python -m pip install –upgrade pip
in cmd.
Edit: This could also be an issue with Visual Studio Code. Try running the python code through CMD.
I installed Anaconda3 so I can create environments and install different packages in each environment. But I fail to understand the difference between the Python in
/usr/bin/python
and
/opt/anaconda3/bin/python
I can seem to access Python 3.6.5 Anaconda from both, why is that? And, what is the difference between both?
Furthermore, I would like to install packages to a single Python environment only.
When you are running python in the terminal, it is looking up your default path to your the python command. In this case, anaconda probably put a line in your shell profile specify the path to the anaconda version, which is why you are seeing it in the interpreter when you run python from either directory.
Secondly, you can set up a conda environment to download app specific dependencies without interfering with your default set up by
conda create --name myenv
source activate myenv
conda install packagename
This will install it in the myenv environment only. To deactivate the environment just run
source deactivate
Here is the documentation on that https://conda.io/docs/user-guide/tasks/manage-environments.html
Judging by your path, you are using Linux which comes with python installed. So /usr/bin/python is default and you have installed the other one later.
For the environments use https://conda.io/docs/user-guide/tasks/manage-environments.html to activate the desired environment, then you can pip install or conda install the packages and it will be places safely only in that environment. Note that spyder icon runs the root environment by default and you have to run it from terminal after activating one of the environments.
Edit:
I'm not sure why you want to use cd to change the python version. I suggest use aliases. I guess you are just changing the path but running the same version of the python anyway. Take a look at this question:
Two versions of python on linux. how to make 2.7 the default
I wanted to create a new virtual environment to install new packages. Following worked for me:
Commands are executed in Jupyter Notebook (OS: Ubuntu 16.04 LTS)
Upgrade pip:
!pip install --upgrade pip
Install virtual environment:
!pip install virtualenv
Select version of Python you want to use in new environment:
I wanted to create an environment with Python version 3. Naming it as Python3_xyz:
!virtualenv -p python3 Python3_xyz
After execution, this will create a folder with the same name in the current working directory (i.e. the location where Jupyter notebook is present)
Create a new option with the name of the created environment
And finally, run the following command:
!python -m ipykernel install --user --name=Python3_xyz
This will create a new option with the name Python3_xyz in the menu from where we create a new notebook.
NOTE: One can run above commands from the terminal as well just don't use '!' before the commands.
This question is bit dated, but since I faced a similar issue, what worked for me might help someone!
I did pip install requests from within my conda environment, but failed to import requests even after trying out everything.
What worked for me: run python -m pip install requests or python3 -m pip install requests within you environment. This installed requests successfully for me.