unable to import coolname and wtforms_components - python

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.

Related

I installed package, but python said No moudel <name-packages> any packages I try to install it

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

ModuleNotFoundError: No module named 'zeep'

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.

How to install python library to specific environment (without conda)

Update update: json_lines is not supported by python versions < 3 - my issue had pretty much nothing to do with environments. I am now using 3.9.1 and all is gucci.
Update: After using which python in my jupyter notebook and in my Terminal, I see that they are both using the same environment. As such I am still at a loss as to why my notebook cannot find json_lines.
I have two python environments on my computer, a default one and one I have for running my jupyter notebook on. I am trying to install the library, json_lines to the latter environment. I am not used the Anaconda environment manager.
On my Mac's Terminal I used the general pip install command pip install json-lines, but when I try to execute the following line of Python import json_lines in my notebook, I still receive the following error ImportError: No module named json_lines.
As I suspect I am not installing to the correct environment, I tried installing the library from inside my notebook with the following, import sys; !{sys.executable} -m pip install jsonlines.
However, this has not changed my dilemma.
Is there some way I can specify from my Terminal which environment to install to? or is it likely I am encountering a different issue to what I suspect?
The package for json_lines in pip in json-lines. Hence you could install it as:
$ pip install json-lines
It may be appropriate to use an isolated python environment for your particular project if you want to use particular conda libraries but without the whole package. In this instance, you would be able to use virtualenv. This will allow you to create an isolated python environment.
$ pip3 install virtualenv
You can call virtualenv to create a virtual python environment with the working name e.g. myvenv.
$ virtualenv myvenv
From here, you can set your terminal to use this python version. If you are on *nix:
$ which python
/usr/bin/python
$ source myvenv/bin/activate
(myvenv)$ which python
/.../myvenv/bin/python
This article can help you out.
https://janakiev.com/blog/jupyter-virtual-envs/
You need to create a virtualenv which will be used by your notebooks.

libraries from pycharm vs pip, python 3.8

Why when I using pip list I am receiving libraries list,
but then i am checking in Pycharm, I have view more there for my project.
It means that using install pip I am installing libraries for all projects , but from Pycharm (in settings) only for selected project?
In PyCharm, you work in a Virtual Environment also known as venv.
Installing packages there will not be installed globally.
For e.g.
In Pycharm, if you run pip install tabulate and then try importing tabulate outside PyCharm, it will show an ImportError and vice-versa
If you want to install that package for all projects, turn on Make available to all projects in project settings or while creating a new project.
To install package outside it, you will need to run pip install <package-name> in Command Prompt

How to install Python packages in a specific environment?

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.

Categories