packages aren't install in project's virtual enviroment - python

i installed django-ckeditor with pip but it goes to the "/home/def-dev/.local/lib/python3.8/site-packages" path when i'm trying to create venv manually.
but when i create project with pycharm it goes to the "./venv/lib/python3.8/site-packages" path
that this path belong's to internal project's venv .
and this make's unknown for pycharm .
what should i do to make pycharm find packages from "/home/def-dev/.local/lib/python3.8/site-packages" or when i'm creating venv manually pip save's packages into "./venv/lib/python3.8/site-packages" path.
when i create venv manually
$ pip3 install django-ckeditor
Requirement already satisfied: django-ckeditor in /home/def-dev/.local/lib/python3.8/site-
packages (5.9.0)
Requirement already satisfied: django-js-asset>=1.2.2 in /home/def-
dev/.local/lib/python3.8/site-packages (from django-ckeditor) (1.2.2)
when i create venv with pycharm
$ pip3 install django-ckeditor
Requirement already satisfied: django-ckeditor in ./venv/lib/python3.8/site-packages (5.9.0)
Requirement already satisfied: django-js-asset>=1.2.2 in ./venv/lib/python3.8/site-packages
(from django-ckeditor) (1.2.2)

Related

Not able to install packages inside the virtual environment,packages get installed in globally

Not able to install packages inside the virtual environment,packages get installed in globally.
Can any body help me on this ?
(venv) c:\Final_Framework\Test_Driven_IO>cd venv
(venv) c:\Final_Framework\Test_Driven_IO\venv>pip install flask
Requirement already satisfied: flask in c:\users\soorya\appdata\local\programs\python\python310\lib\site-packages (2.1.1)
Requirement already satisfied: itsdangerous>=2.0 in c:\users\soorya\appdata\local\programs\python\python310\lib\site-packages (from flask) (2.1.2)
Requirement already satisfied: click>=8.0 in c:\users\soorya\appdata\local\programs\python\python310\lib\site-packages (from flask) (8.1.3)
Requirement already satisfied: Werkzeug>=2.0 in c:\users\soorya\appdata\local\programs\python\python310\lib\site-packages (from flask) (2.2.2)
Requirement already satisfied: Jinja2>=3.0 in c:\users\soorya\appdata\local\programs\python\python310\lib\site-packages (from flask) (3.1.2)
Requirement already satisfied: colorama in c:\users\soorya\appdata\local\programs\python\python310\lib\site-packages (from click>=8.0->flask) (0.4.4)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\soorya\appdata\local\programs\python\python310\lib\site-packages (from Jinja2>=3.0->flask) (2.1.1)
[notice] A new release of pip available: 22.2.2 -> 22.3
[notice] To update, run: python.exe -m pip install --upgrade pip
(venv) c:\Final_Framework\Test_Driven_IO\venv>where pip
C:\Users\soorya\AppData\Local\Programs\Python\Python310\Scripts\pip.exe
(venv) c:\Final_Framework\Test_Driven_IO\venv>
Right now you are using the (default) pip in your standard python installation, not the one in your venv.
You can activate the correct virtual environment if you navigate to the correct path and then use
venv\bin\activate
Please also check in your IDE if you have the correct configuration set / selected the correct interpreter.

Multiple packages cannot install on PyCharm

I am trying to use PyCharm for my python 3 coding on my Linux, and it works great 90% of the time, but I notice that on occasion I cannot import certain packages. For example, when I click Settings->Project->Python Interpreter and try to install 'opencv-python', I get this error:
AttributeError: module 'setuptools.build_meta' has no attribute '__legacy__'
When I try to install opencv-python with pip I get this message:
$ pip install opencv-python
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: opencv-python in ./.local/lib/python3.6/site-packages (4.5.1.48)
Requirement already satisfied: numpy>=1.13.3 in ./.local/lib/python3.6/site-packages (from opencv-python) (1.19.2)
There seems to be some discrepency between the packages my computer has installed and the packages that PyCharm has installed. How can I solve this problem?

Can't run pyinstaller on macos from zsh after installing it

I installed pyinstaller successfully by using pip3 install pyinstaller
Requirement already satisfied: pyinstaller in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (4.2)
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pyinstaller) (49.2.1)
Requirement already satisfied: altgraph in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pyinstaller) (0.17)
Requirement already satisfied: macholib>=1.8; sys_platform == "darwin" in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pyinstaller) (1.14)
Requirement already satisfied: pyinstaller-hooks-contrib>=2020.6 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pyinstaller) (2020.11)
and btw, my echo $PATH returns:
/Users/apple/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin
However, when I try to run this following code in my terminal in the same directory, it doesn't work:
apple#apples-MBP-2 app4.1_using_OOP % pyinstaller --onefile --windowed frontend.py
and it has the error:
zsh: command not found: pyinstaller
I tried many ways including:
Downgrading pip to 18.1 and run pip3 install pyinstaller again
Used apple#apples-MBP-2 app4.1_using_OOP % python -m PyInstaller frontend.py and it does run and has a disc folder where there is a file named frontend.app, but I can't open it.
Questions:
Why sometimes I can directly use the modules downloaded by pip3 but sometimes I can't?
If I want to add to my $PATH, do I add /Library/Frameworks?
I had the same issue. This command worked for me:
python3 -m PyInstaller your_script.py

How to uninstall a package which can't be found in /usr/local/lib

I was following the Flask tutorial and at some point installed an 'incomplete' version of the flaskr micro-blogging app. I would like to 'overwrite' this installation with one obtained from https://github.com/pallets/flask/tree/master/examples/flaskr.
However, in the directory ~/dev/scratch/flask/examples/flaskr, if I try to run
sudo pip install --editable .
I get the following:
The directory '/home/kurt/.cache/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 '/home/kurt/.cache/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.
Obtaining file:///home/kurt/dev/scratch/flask/examples/flaskr
Requirement already satisfied: flask in /usr/local/lib/python2.7/dist-packages (from flaskr==0.0.0)
Requirement already satisfied: itsdangerous>=0.21 in /usr/local/lib/python2.7/dist-packages (from flask->flaskr==0.0.0)
Requirement already satisfied: click>=2.0 in /usr/local/lib/python2.7/dist-packages (from flask->flaskr==0.0.0)
Requirement already satisfied: Werkzeug>=0.7 in /usr/local/lib/python2.7/dist-packages (from flask->flaskr==0.0.0)
Requirement already satisfied: Jinja2>=2.4 in /usr/lib/python2.7/dist-packages (from flask->flaskr==0.0.0)
Requirement already satisfied: MarkupSafe in /usr/lib/python2.7/dist-packages (from Jinja2>=2.4->flask->flaskr==0.0.0)
Installing collected packages: flaskr
Found existing installation: flaskr 0.0.0
Can't uninstall 'flaskr'. No files were found to uninstall.
Running setup.py develop for flaskr
Successfully installed flaskr
Apparently, pip found an 'existing installation' which it can't uninstall. I'd like to 'wipe out' this installation; however, if I try search for it using, in the directory /usr/local/lib,
find . -name '*flaskr*'
the only result I get is
./python2.7/dist-packages/flaskr.egg-link
If I rm this file, it seems to 'come back' automatically.
How can I re-install the 'flaskr' app cloned from its Github repository?
I solved the problem by going back to the directory I had installed the 'incomplete' version of flaskr from, and running the command
sudo python setup.py develop --uninstall
which produced the confirmation
running develop
Removing /usr/local/lib/python2.7/dist-packages/flaskr.egg-link (link to .)
Link points to ['/home/kurt/dev/scratch/flask/examples/flaskr', '.']: uninstall aborted
Then, going back to the directory with the 'complete' version (~/dev/scratch/flask/examples/flaskr), I ran sudo pip install --editable . followed by export FLASK_APP=flaskr. Then the command
flask initdb
prints the expected output
Initialized the database.

python-Can't use modules installed by Homebrew?

I want to use the essentia module in my python virtualenv and the version of python is 2.7.6.
After I executed
brew tap MTG/essentia
I can't find this module in my Pycharm.
I've also tried to install other package such as matplotlib using
sudo pip install matplotlib
under my virtualenv path.
The directory '/Users/username/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/username/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.
Requirement already satisfied (use --upgrade to upgrade): matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): tornado in /Library/Python/2.7/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Collecting nose (from matplotlib)
/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading nose-1.3.7-py2-none-any.whl (154kB)
100% |████████████████████████████████| 155kB 46kB/s
Requirement already satisfied (use --upgrade to upgrade): backports.ssl-match-hostname in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied (use --upgrade to upgrade): singledispatch in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied (use --upgrade to upgrade): certifi in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied (use --upgrade to upgrade): backports-abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib)
Installing collected packages: nose
Successfully installed nose-1.3.7
You are using pip version 7.1.2, however version 8.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
I checked in Pycharm, however, in the interpreter there was no matplotlib module.
How can I install packages in my virtualenv?
If the pip package is not available, you can find the brew installation in your local python directory.
Quick Fix:
Install essentia to your local environment.
Append the local essentia package to your virtual environment
sys.path.append('/usr/local/lib/python2.7/site-packages')
import essentia
Long Fix:
If you want to fully contain the packages in your virtual environment, try copying the local site-packages/essentia folder to your virtual environment
Copy over any other dependencies such as site-packages/numpy. Check brew's Cellar (/usr/local/Cellar) for other dependencies
You should not install python modules with brew, instead you should use pip. The following method has worked for me in OSX.
Desktop $ virtualenv myproject # Create the virtual environment
Desktop $ cd myproject # Change into that directory
Desktop $ source bin/activate # Enter the virtual environment
(myproject) $ sudo pip install matplotlib # Install matplotlib
(myproject) $ deactivate # Exit from the virtual environment
Look here for a further explanation of virtualenv.

Categories