linking python project with virtualenv - python

I have an ubuntu server 12 running as a guest in virtualbox on a windows 7 host.
In a shared folder /workspace I have a python project project01. Since virtualbox has issues with creating symlinks in a shared folder I created the virtualenv in my users home directory. /home/user1/venv.
I can activate the virtual environment no problem.
source ~/venv/bin/activate
but when I try to run manage.py, I get an error
~/venv/bin/python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
I'm sure I'm missing a path or something, but I'm not sure exactly what path to add and to where. I tried setting PYTHONPATH in the activate script, but that didn't work. Do I need to add the path to django's core management in the activate script?
I see a bunch of django directories under venv/build
Django
django-appconf
django-celery
django-celery-email
django-celery-transactions
django-debug-toolbar
django-filebrowser
django-grappelli
djangohelpers
django-imagekit
django-pipeline
django-redis
django-sslify
django-storages
django-widget-tweaks
do I need to point in there somewhere?
I'm very much a django and virtualenv noob.
UPDATE
It doesn't look like the packages were installed. So this is another matter entirely.
Thanks for your reply. I have some other issues I need to figure out here.
I was in the virtualenv and ran pip install -r requirements.txt which only had 1 error for postgres, but I'm not using a local postgres server so that's not a huge deal. Unless that error is preventing everything from installing, then it is a huge deal.
when I check site-packages I only see the following:
easy-install.pth
pip-1.2.1-py2.7.egg
setuptools-0.6c11-py2.7.egg
setuptools.pth
and pip freeze shows me:
argparse==1.2.1
wsgiref==0.1.2
the error from pip install is:
Exception information:
Traceback (most recent call last):
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/basecommand.py", line 107, in main
status = self.run(options, args)
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/commands/install.py", line 256, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 1042, in prepare_files
req_to_install.run_egg_info()
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 236, in run_egg_info
command_desc='python setup.py egg_info')
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/util.py", line 612, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in venv/build/psycopg2

The error looks as if you do not have Django in the venv python path.
You can confirm that it is part of your venv python install using a couple of ways:
If you used PIP to install you can verify that the package is installed using pip freeze
Also check in lib/python2.7/site-packages/ of the venv there should be a django directory in there. This is the directory that is part of the PYTHONPATH for your venv.
If you cannot find the modules in there of have installed them in a different path. Then you will need to make sure that the path is part of the PYTHONPATH of the venv.

Related

ModuleNotFoundError: No module named 'dnf' when running yum or dnf

A few days ago I wanted to run dnf but I received the following error
Traceback (most recent call last):
File "/usr/bin/dnf", line 57, in <module>
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
Thus I tried to run yum and I received something similar:
Traceback (most recent call last):
File "/usr/bin/yum", line 57, in <module>
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
I do not know what happened and I hope someone can help me find the problem and solve it. The only thing I know is that it might be related to the fact that a few days before I installed tensorflow in python using conda. Although it seems conda does not work now because I get this:
Traceback (most recent call last):
File "/usr/bin/conda", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
#_call_aside
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 581, in _build_master
ws.require(__requires__)
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 898, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 784, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'conda==4.5.11' distribution was not found and is required by the application
I am using fedora 29
Thanks!
I had the same problem, but after all trial and error the only thing actually worked was:
rpm -qa python3
This will announce your python3 rpm package.
I've searched and downloaded it from web
Go to the downloaded directory like:
sudo rpm -e --nodeps python3-3.7.2-4.fc29.x86_64(my python3 rpm package)
sudo rpm -i python3-3.7.2-4.fc29.x86_64.rpm
I tried many other methods so this'll not be a only factor that resolve that problem.
Hello,
i have just been through this in Fedora 31 and do not exactly know what was the cause that led to this same issue, it must have been some package managing over another context that came up only on my next need to use DNF.
I am assuming that before this stated error:
Traceback (most recent call last):
File "/usr/bin/dnf", line 57, in
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
You were having this message when executing dnf:
/usr/local/lib/python3.7/site-packages/dnf.py:15: UserWarning: The DNF Python API is not currently available via PyPI.
Please install it with your distro package manager (typically called
'python2-dnf' or 'python3-dnf'), and ensure that any virtual environments
needing the API are configured to be able to see the system site packages
directory.
After some hours researching and trying to install each DNF rpm dependency of the DNF rpm itself(https://pkgs.org/download/dnf) i felt as an intuition that maybe i should try to remove(mv sure)
/usr/local/lib/python3.7/
which had just one folder in it named site-packages
It worked!
Thank you.
I have a friend who met the same problem.
He tried to uninstall python3.7 in linux server by some amazing cmd rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps and whereis python3 |xargs rm -frv.
This caused the yum and dnf to break.
I changed the /usr/bin/yum to use a local python3.8 version, but it caused ModuleNotFoundError: No module named 'dnf' at last, and didn't solved it.
It is not a good way to download many rpm packages on the Internet. And I can't use yum either. But I have another same linux OS server, so I've tried to copy the correlation files about python3.7.
$ rpm -ql python3-3.7.0-9.h4.eulerosv2r8.aarch64> py.log
$ while read -r line;do dirname $line |xargs -I {} ssh root#$remoteip "mkdir -p {}" ;scp $line root#$remoteip:$line ;done<py.log
$ rpm -ql python3-libs-3.7.0-9.h4.eulerosv2r8.aarch64 >pylib.log
$ while read -r line;do dirname $line |xargs -I {} ssh root#$remoteip "mkdir -p {}" ;scp $line root#$remoteip:$line ;done<pylib.log
scp -r /usr/lib/python3.7/site-packages root#$remoteip:/usr/lib/python3.7/
I recovered yum this way.
I had the same issue.
For me the solution was to simply uninstall the python3 dnf package (including from all virtualenvs) that I had obviously installed somewhen.
pip uninstall dnf
had the same error.
my fix ->
cd into /usr/bin. has many python files...
latest python (3.11) has pytest, python3 -> python3.11 (symlink), python3.11, python3.11-config, python3.11-x86_64-config, python -> python3
had been using 3.9, not familiar with python so much, so changed symlink back to python3->python3.9 after Fedora 36 update changed symlink to 3.11 and installed python3.11. when i changed symlink back to 3.9, this created the error message. When i changed the symlink back to python3->python3.11 the error disappeared and all works fine. DNF is fine etc. did nothing else.
since all the other python files were pointing to the 3.11 versions, introduction of the symlink to 3.9 must have blown the fuse...

Ansible commands work when root, but not when default user. Throws a python PyYAML error only as default user, but then works for root

I recently ran some PIP commands in my server, and after doing so none of the Ansible commands would work as the default user. If I try to run any Ansible commands as the default user, I get the following error -
Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 4, in <module>
from pkg_resources import require; require('ansible==2.2.0')
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2659, in <module>
parse_requirements(__requires__), Environment()
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 546, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: PyYAML
However, if I sudo and then try to run any ansible commands, it seems to work fine. I think I might have messed something up with the python packages that were installed with PIP, and now they only work for root.
How can I get the default user to be able to run these commands again?
Fixed it. The issue was with permissions when I ran the pip install. Running
chmod -R ugo+rX /usr/lib64/python2.6/site-packages/ and
chmod -R ugo+rX /usr/lib/python2.6/site-packages/ fixed the issue.

Pycharm Virtulenv "non-zero exit code" after install wheel or module from pip

After installing kivy via a wheel i came upon an error in Pycharm when i refreshed my virtual env for python 3.4. The error is in the section
Pycharm: Projects ->
Project Interpreter -> [Virtualenv packages]
Error/warning along the bottom shows "non-zero exit code"
My environment:
Windows 8.1 64-bit
Python 3.4.3 32-bit
Pycharm 4.5.4
Virtual env - 3.4.3
This happened after i installed a wheel from "http://www.lfd.uci.edu/~gohlke/pythonlibs/" (which is an awesome site... check it out) from the command line.
first i installed pygame from the downloaded wheel file located at"http://www.lfd.uci.edu/~gohlke/pythonlibs/:
C:\Users\<user_name>\3.4Python_32Bit\Scripts> pip3.4.exe install C:\Users\<user_name>\Downloads\pygame-1.9.2a0-cp34-none-win32.whl
next i adjust the cython version:
C:\Users\<user_name>\3.4Python_32Bit\Scripts> pip3.4.exe install -I Cython==0.21.2
then i installed kivymd & kivy garden via the pycharm virtualenv interface within pycharm - both installed successfully.
Finally i tried to install "kivy"
The results were initially good, it showed installed, the package loaded in the virtualenv within pycharm, but when i reloaded the virtualenv in pycharm to associate it to a package the pycharm interface showed "non-zero exit code." How can this be fixed, there is no other errors visible?
The way this can be solved is by running the python from said environment
i.e.
C:\Users\<user_name>\3.4Python_32Bit\Scripts>python.exe C:\Users\<user_name>\3.4Python
_32Bit\Lib\site.py
The output will tell you what package you have that has failed when it gathers the packages from the "C:\Users\\3.4Python_32Bit\Lib\site-packages":
Failed to import the site module
Traceback (most recent call last):
File "C:\Users\<user_name>\3.4Python_32Bit\Lib\site.py", line 703, in <module>
main()
File "C:\Users\<user_name>\3.4Python_32Bit\Lib\site.py", line 683, in main
paths_in_sys = addsitepackages(paths_in_sys)
File "C:\Users\<user_name>\3.4Python_32Bit\Lib\site.py", line 282, in addsitepack
ages
addsitedir(sitedir, known_paths)
File "C:\Users\<user_name>\3.4Python_32Bit\Lib\site.py", line 204, in addsitedir
addpackage(sitedir, name, known_paths)
File "C:\Users\<user_name>\3.4Python_32Bit\Lib\site.py", line 173, in addpackage
exec(line)
File "<string>", line 1, in <module>
KeyError: 'kivy'
In order to use your environment minus the package causing the issue is the remove the folder directly related to this error, in this case kivy:
remove C:\Users\<user_name>\3.4Python_32Bit\Lib\site-packages
If you want to reinstall the package confirm that you have the right dependencies, wheel(if this is what you are using), or you have the correct versions of installed packages. Then reinstall as needed.This can be applied to other packages with the same issues.

Manually installing python dependencies doesn't work. Why?

Whenever I install my python project using 'python setup.py install', and invoke my project on a CentOS vagrant box, it works great. The dependencies get resolved perfectly.
However, if I create an rpm using fpm for my project, install the rpm using 'rpm -i rpm-file.rpm', manually install the dependencies using 'pip install -r requirements-file-path.txt' and then invoke my project on another CentOS vagrant box, I get the following error:
File "/usr/bin/<name-of-my-project>", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2655, in <module>
working_set.require(__requires__)
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 648, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 546, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: fabric==1.10.2
Uninstalling the dependencies using 'pip uninstall' and reinstalling them doesn't fix the problem. What am I missing?
Just found the answer on the Fabric FAQ page: http://www.fabfile.org/faq.html/. Executing:
sudo pip install -U setuptools
Then re-installing the dependencies and project solved my problem. But welcome to other answers.

Why am I getting this error (related to pip and easy_install) when trying to setup a virtualenv?

I'm trying to create a Flask application to push to Heroku. When I try to create a virtualenv in the folder, I'm thrown this error:
photo-crawl › sudo virtualenv venv --distribute
Password:
New python executable in venv/bin/python
Installing distribute............................................................................................................................................................................................................................done.
Installing pip....
Complete output from command /Users/evansiegel/In...rawl/venv/bin/python -x /Users/evansiegel/In...env/bin/easy_install /Library/Python/2.7/...ort/pip-1.2.1.tar.gz:
/Users/evansiegel/Involvio/photo-crawl/venv/bin/python: can't open file '/Users/evansiegel/Involvio/photo-crawl/venv/bin/easy_install': [Errno 2] No such file or directory
----------------------------------------
...Installing pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.8.4', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 964, in main
never_download=options.never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1076, in create_environment
install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 667, in install_pip
filter_stdout=_filter_setup)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1042, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/evansiegel/In...rawl/venv/bin/python -x /Users/evansiegel/In...env/bin/easy_install /Library/Python/2.7/...ort/pip-1.2.1.tar.gz failed with error code 2
It seems that for some reason virtualenv is not putting everything it should be putting into the venv/bin folder. Right now, only python and two aliases, python2 and python2.7 are in there.
Thanks!
I believe this is caused by a bug in older versions of virtualenv and/or pip. It looks like you're using virtualenv 1.8.4 and pip 1.2.1. Is it possible for you to upgrade to latest virtualenv and pip (currently virtualenv 1.9.1 and pip 1.3.1)?
This should do it, if you have install privileges:
pip install pip --upgrade
pip install virtualenv --upgrade
At that point running the same command (i.e. sudo virtualenv venv --distribute) should give you what you want.

Categories