When I install bcfg2 - http://bcfg2.org using
pip install git+git://git.mcs.anl.gov/bcfg2.git#egg=Bcfg2
or
pip install bcfg2
I am able to get bcfg2 working. Calling sudo bcfg2-admin init, shows me the set-up configuration steps/stdin prompt as expected.
When I introduce the -e option like this (in a new/clean virtualenv),
pip install -e git+git://git.mcs.anl.gov/bcfg2.git#egg=Bcfg2
And I attempt to call sudo bcfg2-admin init, I get an error message:-
calvin$ bcfg2-admin init
Traceback (most recent call last):
File "/Users/calvin/.virtualenvs/bcfg2/bin/bcfg2-admin", line 7, in <module>
execfile(__file__)
File "/Users/calvin/.virtualenvs/bcfg2/src/bcfg2/src/sbin/bcfg2-admin", line 6, in <module>
import Bcfg2.Server.Core
ImportError: No module named Bcfg2.Server.Core
This leads me to think that there is something wrong with the way setup.py is written for bcfg2. The file is located here - https://github.com/Bcfg2/bcfg2/blob/master/setup.py
Appreciate any input from pythonistas who are experts with python packaging and the configuration of setup.py.
You've installed to a virtual environment (-e). However when you run this with sudo python gets executed as root without the virtual environment available.
If you run sudo su you should be dropped into a root shell. You can then activate the virtual environment and run bcfg2-admin.
The setup.py has a bug.
Figured it out, fixed it and sent a pull request to bcfg2 maintainers.
Reference - https://github.com/Bcfg2/bcfg2/pull/28
Related
I have built python3.8.12 from source and installed it in /python3 on a machine with no other python anywhere. there are no "system" packages. (it is rocky8.5 linux)
Now I create and activate a venv from that python:
/python3/bin/python -m venv myvenv
source myvenv/bin/activate
Now I install packages in this venv from a local repository
pip install -r requirements.txt --index-url=file:///python3/pypkgs/simple
The repository was built with pip2pi. this is all being designed for full airgap deployments.
Now I cannot import selinux as it is apparently not aware of the selinux in the venv, and is instead searching the system.
(myvenv) [root#node1]# python -c "import selinux"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/root/myvenv/lib/python3.8/site-packages/selinux/__init__.py", line 104, in <module>
check_system_sitepackages()
File "/root/myvenv/lib/python3.8/site-packages/selinux/__init__.py", line 100, in check_system_sitepackages
raise Exception(
Exception: Failed to detect selinux python bindings at ['/python3/lib/python3.8/site-packages']
I use the selinux package as an example because it is the issue I am currently faced with. Not sure if this is a wider problem yet. Haven't tested exhaustively, but have not had issue with any other package.
Ok I guess I got it working. Not sure how horrendous of a fix this is.
First, I installed selinux to the system /python3 (apparently you can't use selinux within a venv - has to be system level?)
And then I hardcoded my /python3/bin/python to this line: https://github.com/pycontribs/selinux/blob/321d66619ed59bec00a9dc6216ce417d7befec41/selinux/__init__.py#L76
I try to upgrade pip within a virtualenv following the instructions here. The upgrade fails because the system python cannot import the name Message from the email module.
(newsfeed)myhost:newsfeed admin$ pip install --upgrade pip
Traceback (most recent call last):
File "/Users/admin/newsfeed/newsfeed/bin/pip", line 7, in <module>
from pip import main
File "/Library/Python/2.7/site-packages/pip/__init__.py", line 9, in <module>
from pip.log import logger
File "/Library/Python/2.7/site-packages/pip/log.py", line 8, in <module>
from pip import backwardcompat
File "/Library/Python/2.7/site-packages/pip/backwardcompat/__init__.py", line 69, in <module>
from email import Message as emailmessage
ImportError: cannot import name Message
This problem is not just with upgrading pip but with installing anything within the virtualenv. When new package installations are attempted the same error occurs.
In a python terminal outside the virtualenv Message cannot be imported, but inside the virtualenv it can.
Also, in a different virtualenv on the same machine, there is no error installing or upgrading packages.
Why can't this virtualenv upgrade or install packages?
The standard library's email package is being shadowed (hidden) by a package or module named email(.py) in your path.
Locate the package by calling
python -c 'import email;print(email.__file__)'
and rename it or remove it.
Your pip is not inside the venv so you will probably not be able to upgrade it like this.
This is caused by the fact that you created a venv that uses system-packages. Remove the venv and recreate it by adding --no-site-packages as a parameter.
Followed instructions on the github page. Of course, had to make minor changes since I was working with a windows 7 system. I got to the point post creating the virtual environment for portia to run. And I was trying to install the required packages using pip.
pip install -r requirements.txt
It failed with a log.
Now in the shell I try to run twistd, it gives error saying command not found. I even tried as follows:
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$ python ../../portia_env/Scripts/twistd.py -n slyd
Traceback (most recent call last):
File "../../portia_env/Scripts/twistd.py", line 13, in <module>
from twisted.scripts.twistd import run
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 53, in
<module>
_checkRequirements()
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 37, in
_checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zop
e.interface.
(portia_env)
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$
Is there an alternate procedure to follow in order to make this work on windows?
It looks like zope.interface didn't install when you ran:
pip install -r requirements.txt
Could you try running the following and see if it works?
pip install zope.interface
I am trying to use pip on my Redhat system.
I installed pip following the instructions here, but when I try to use it, for example pip install, I get the following error code:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in ?
from pip import main
ImportError: No module named pip
this issue due to common user do not have privilege to access packages py file.
1. root user can run 'pip list'
2. other common user cannot run 'pip list'
[~]$ pip list
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal
solution :
root user login and run
chmod -R 755 /usr/lib/python2.7
fix this issue.
If pip is already installed and your unable to access it, one of the reason could be that you don't have permissions to read or execute the library. Try doing
sudo chmod -R u+rx /usr/lib/python2.7/site-packages/pip/
If pip is installed in a different folder, you can obtain the folder path by doing
>>> import pip
>>> pip.__path__
['/usr/lib/python2.7/site-packages/pip']
If you don't have root rights and running on python 2.6 then you can try this file https://bootstrap.pypa.io/2.6/get-pip.py (it is from same instruction you used, it is a simple python script which installs all dependencies and pip itself) and run it with command python get-pip.py --user
I am trying to install Exscript from github.
pip install -e 'git+git://github.com/knipknap/exscript.git#egg=Exscript'
...
Successfully installed Exscript
Cleaning up..
When i try to load it, python is not able to find it:
python2.7 -c "import Exscript"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named Exscript
But, when i try to install it in the same virtualenv with setup.py it installs and loads successfully.
What am i doing wrong?
The flag -e means "editable", and what happens behind the scenes is a symlink, and as I see, Exscript uses a directory named src, what is not seen a good practice[1].
So, in order to solve your problem, you have two alternatives:
Remove -e flag
Change Exscript to get rid of src, and use another directory name
Take a look at https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/creation.html#arranging-your-file-and-directory-structure and https://setuptools.readthedocs.io/en/latest/userguide/development_mode.html.
[1]: the good practice is to have the directory as the same name as used when importing the package