libraries from pycharm vs pip, python 3.8 - python

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

Related

unable to import coolname and wtforms_components

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.

How does PyCharm find libraries installed with pip

I'm using PyCharm and also installing dependencies with pip I dont know how to make PyCharm to get this new dependencies that I install and are in the folder {project_base}/env/lib/python3.9
If I go there I can see the libraries installed, but PyCharm is not able to seen it, and allow me to use it in the code.
I've seen in the preference the Python Interpreter section, but I need to use pip, since I'm documenting the package to install with pip for other users.
Any idea how to point my PyCharm to my env/lib/ folder?
Regards
When you choose Python Interpreter, PyCharm will automatically pick up libraries available on that Python installation.
Make sure PyCharm uses the Python Interpreter that has its libraries installed in env/lib/python3.9 and then you should see available libraries on the interpreter configuration screen.
If you install libraries with pip e.g. env/bin/python -m pip install mylib they will become automatically available to PyCharm, because PyCharm and pip will use the same Python installation to manage these libraries.

List python packages installed with pip install <package> --target <someDir>

I installed python packages at a custom location using pip's option --target. The packages are imported and working fine in my python program which imports the modules. However, when I try to see the modules in my environment using 'pip list', those modules don't show up.
I am using a virtual environment and I ensured that I am in the virtual environment when I issue 'pip list' command

No module named win32com

I've just installed Python for the first time and I'm trying to reference the win32com module however, whenever I try to import it I get the message "no module name win32com".
Any ideas?
the below plus add pywin32 in PyCharm setting work for me
python -m pip install pywin32
As it is not built into Python, you will need to install it.
pip install pywin
Since win32com is a Windows-specific package, this answer will be geared towards Windows users.
Option 1: Install locally with pipenv (recommended)
You can use a package manager like pipenv to manage your dependencies.
Ensure you have pipenv installed (pip install pipenv).
In your project directory, run pipenv install pypiwin32 to install the package.
Now you can run your code using commands like the following pipenv run main.py
Example main.py code:
import win32com
print(win32com)
Option 2: Install locally with venv (recommended)
If pipenv isn't your thing, you can use the built-in virtual environments.
From your project directory, run python -m venv venv to setup you virtual environment.
Run venv\Scripts\activate.bat from your project directory whenever you want to use this virtual environment (you will see (venv) added to your shell prompt to know it's activated).
Run pip install pypiwin32 from your active virtual environment to install the package.
You can run your code like python main.py so long as the virtual environment is active.
Option 3: Install globally (typically not recommended)
This is not typically recommended, but included anyway.
Using pip install pypiwin32 you can install the package globally.
Then you can run your code with just python main.py.
This will work as well
python -m pip install pywin32
You should try using pip this way:
pip install pypiwin32
It is pypiwin32 which should work.
When working with python projects its always a good idea to create a so called virtual environment, this way your modules will be more organized and reduces the import errors.
for example lets assume that you have a script.py which imports multiple modules including pypiwin32.
here are the steps to solve your problem:
1. depending on you operating system you need to download and install virtualenv package, in debian its as simple as sudo apt install virtualenv .
2. after installing 'virtualenv' package go to your project/script folder and create a virtualenv folder with virtualenv venv it creates a folder named venv in that directory.
3. activate your virtualenv source /path/to/venv/bin/activate if your already in the directory where venv exists just issue source venv/bin/activate
4. after activating your venv install you project dependencies pip install pypiwin32 or pip install pywin
5. run your script, it wont throw that error again :)

How to install packages in different version of python?

I have a MacBook Pro that came pre-installed with python2.7. I later installed python3 and ipython notebook. I installed pip too to install packages, and am able to install packages and run program from python3. However, for another project I need to run code in python2.7, and I am not sure how to install it in python2.7 folder.
I tried using pip for installing packages to 2.7, but it kept giving error saying package already exists. When I check for version of python using --version, I see 2 pythons installed. However, when I check for pip and pip3, both seem to be in th same folder.
Any tips on how to install packages in python2.7, without making any changes to 3.3? I am using python3 and ipython notebooks for another project.
viveks-mbp:~ vivekyadav$ which pip
/Library/Frameworks/Python.framework/Versions/3.3/bin/pip
viveks-mbp:~ vivekyadav$ which pip3
/Library/Frameworks/Python.framework/Versions/3.3/bin/pip3
viveks-mbp:~ vivekyadav$ which python
/usr/bin/python
viveks-mbp:~ vivekyadav$ which python3
/Library/Frameworks/Python.framework/Versions/3.3/bin/python3
You can use the virtualenv to create a kind of sandbox.
$ virtualenv <work-directory>
$ source <work-directory>/bin/activate
The last command initiate your virtual environment, totally isolated from the system. So every pip command will install the package inside this directory.
But you have to run your application inside the virtual environment too.

Categories