I try to install PyTables package using easy_install.
My problem is that I am not root on the system and am not allowed to write to /usr/local/lib/python2.7/dist-packages/ directory.
To solve this problem I decided to install locally. For that I have created a new directory: /home/myname/mylibs. Then I executed easy_install -d /home/myname/mylibs tables. As a result easy_install complained about the PYTHONPATH environment variable. To resolve this problem I added my new directory to the PYTHONPATH and repeated the previous command. As a result I get syte.py and syte.pyc file in my /home/myname/mylibs directory.
However, when I try import tables from Python it still does not work. What also worries me is that the new files do not have "table" in their names as well in their content.
Can anybody, please, explain me what is going on?
I had a similar problem recently trying to use easy_install to put packages in a location I had write-access to. Like you, I had to add the location to my PYTHONPATH variable to get it to install. It was then necessary to set PYTHONPATH every time I wanted to run a command using the installed package(s).
For example, to install and use the flask package I needed to do this:
$ PYTHONPATH=/tmp easy_install -d /tmp flask
$ PYTHONPATH=/tmp python -c 'import flask; print(flask.__version__)'
0.10.1
Without the PYTHONPATH variable set you'd get an error:
$ python -c 'import flask; print(flask.__version__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named flask
You can of course set the variable permanently by running:
$ export PYTHONPATH=/tmp
Or putting export PYTHONPATH=/tmp in your ~/.bashrc file.
Related
For some odd reason no matter which package I install when I go to import it doesn't know what package I'm talking about. I am very certain this is a Visual Studio Code error but if not I am also using Linux.
When I pip install the package pyttsx3 this is what I get in the Terminal:
Collecting pyttsx3
Downloading https://files.pythonhosted.org/packages/24/4e/580726c73272344d3e74b7aaffae55ff6b6450061fbecb8cc6e112531c02/pyttsx3-2.7.tar.gz
Building wheels for collected packages: pyttsx3
Running setup.py bdist_wheel for pyttsx3 ... done
Stored in directory: /home/secretlloyd/.cache/pip/wheels/a2/8a/fe/11112aca9c89142c3a404bc67ef3393a7ad530da26639a05d4
Successfully built pyttsx3
Installing collected packages: pyttsx3
Successfully installed pyttsx3-2.7
But when I run a example I get this error:
Traceback (most recent call last):
File "/home/secretlloyd/Visual Studio Code/Python/Finished/Text Colors/finished.py", line 1, in <module>
import pyttsx3
ModuleNotFoundError: No module named 'pyttsx3'
You can use an virtual environment to install your libs. If you do that, each project will have its own scoped libs without affect your global libs.
How to use the virtual environment?
Enter the root folder of your project and then run the following commands on the bash:
$ py -m venv .env
$ source .env/Scripts/activate
After that you'll notice your bash will have a prefix like that (.env). Then you should install your libs:
(.env) $ pip install pyttsx3
In order to deactivate the virtual environment just run the following command:
(.env) $ deactivate
Setup VS Code Intellisense for Virtual Environment
If you're using VSCode you can set the correct python interpreter after setting up a virtual environment. Just follow the steps:
Open VSCode in your project
Press F1
Type: > python: select interpreter
Click on Enter path or find an existing interpreter
Click on Find
The navigate to .env > Scripts > python
3 possible cases:
The same thing happened to me when I did not notice I was using two Pythons at the same time one 2.7 and another one 3.6. Make sure to know where is your package being installed to the Python modules folder you really want to store it or in another one you did not know existed.
Your PATH might not be configured correctly, check out either if you are using Windows or Linux if your PATH variables are configured correctly. You can reset your configuration if you wish. (link= How to reload .bashrc settings without logging out and back in again?)
For some packages/libraries of Python the way of importing the library is different from the name you import it on your .py file. For example: You can install OpenCV library by [pip install OpenCV] but when importing it in a file you have to write [import cv2].
I hope you find this information helpful for your problem.
I've attempted to start writing Python in WSL, but the whole experience has been super messy. To install packages, I know I want to use pip3, but any pip3 commands result in
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
My work-around has been to use the following command to install, which has worked:
python3 -mpip install --user somePackageName
My real confusion now comes from the fact that the which command is not locating packages installed by the above command. However, I know they are there as they appear when I run 'python3 -mpip freeze'. Is this because they are installed locally?
(Also If anyone has experience with Python and pip in WSL and could weigh in on how to go about configuring my Python environment, in order to avoid these types of issues, that would be super helpful.)
Thanks!
Try: python -m site
(perhaps replacing python by python3, etc)
You should get a short output with the following block,
From Windows:
sys.path = [
'<your current working directory>',
'C:\\Python38a2\\python38.zip',
'C:\\Python38a2\\DLLs',
'C:\\Python38a2\\lib',
'C:\\Python38a2',
'C:\\Python38a2\\lib\\site-packages',
]
From WSL:
sys.path = [
'<your current working directory>',
'/usr/lib/python37.zip',
'/usr/lib/python3.7',
'/usr/lib/python3.7/lib-dynload',
'/home/<username>/.local/lib/python3.7/site-packages',
'/usr/local/lib/python3.7/dist-packages',
'/usr/lib/python3/dist-packages',
]
That's where you'll want to look for installed packages.
The order here is the import precedence (earlier entries "trump" later ones)
For pip installed packages, you'll generally want to look in the site-packages directory.
For <package manager> installed packages you'll generally want to look in the dist-packages directory.
Lastly, which is generally used to find executables on your $PATH environment variable (and, at least for me, requires that they have the executable bit set to appear in the results).
Here, you're looking for something different, modules or packages that are importable by Python. In other words, modules or packages on your $PYTHONPATH.
These are two different types of "path"s.
Inside your interpreter, $PYTHONPATH maps to sys.path and $PATH maps to os.environ['PATH'].
I'm using Amazon linux, and I followed some steps for using letsencrypt that easily found in google search, but all it fails with:
Error: couldn't get currently installed version for /root/.local/share/letsencrypt/bin/letsencrypt:
Traceback (most recent call last):
File "/root/.local/share/letsencrypt/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/root/.local/share/letsencrypt/local/lib/python2.7/dist-packages/certbot/main.py", line 11, in <module>
import zope.component
File "/root/.local/share/letsencrypt/local/lib/python2.7/dist-packages/zope/component/__init__.py", line 16, in <module>
from zope.interface import Interface
ImportError: No module named interface
What I do is:
# git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
# /opt/letsencrypt/letsencrypt-auto --debug
That's it. So I tried to fix this, but dozens of solution that I found all won't worked to me.
Most of them said try this:
unset PYTHON_INSTALL_LAYOUT
But still got same error, nothing changes. And someone said that type this:
pip install --upgrade pip
But after typed that, I can't use pip anymore, it failed with some kind of command not found error, so I had recreated my server again.
I also tried to use CertBot, but it gives me exactly same error!
I'm using Linux 4.4.51-40.58.amzn1.x86_64 x86_64, need a help. I spent almost a day, but nothing progressed.
Every solution that I was found were not worked to me. Any advice will very appreciate it.
Removing certbot directory did the trick for me.
rm -rf /opt/eff.org/certbot/
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
sudo ./certbot-auto certonly --standalone -d example.com --no-bootstrap
I had same issue and after a long run, a very simple thing solved this issue on my AWS instance:
Move the letsencrypt cache files to another folder (considering you run it as root/sudo):
sudo mv /root/.local/share/letsencrypt /root/.local/share/letsencrypt-old
Downloaded a brand new version of letsencrypt
git clone https://github.com/letsencrypt/letsencrypt
Run the letsencrypt command to test if its working again:
sudo ./letsencrypt-auto --debug
During my search for a solution I also updated pip which might have helped. Although my attempts after pip update did not solved my issue in the same way as cleaning up the letsencnrypt cache folder.
I hope this helps. If not, some links I can share about same issue:
certbot zope.interface error
no module named interface
letsencrypt failed with no module named interface
Part of the issue for me was related to some strange default behavior around 64 bit packages installing, but not being picked up by python. After getting this issue [it's mostly installed at this point], run the following
cd /root/.local/share/letsencrypt
\cp -r ./venv/lib64/* ./venv/lib/
Then retry the command. The install locations of the python virtual environment change with different versions and operating systems, but the general principle has helped me debug two different installs.
I have also faced this issue multiple times and every time I have to repeat these following steps:
Remove cache:
sudo rm -rf /root/.local/share/letsencrypt/
sudo rm -rf /opt/eff.org/certbot/`
then,
unset PYTHON_INSTALL_LAYOUT
Install Let’s Encrypt by cloning the github repository into /opt/letsencrypt
git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
then run installer again
/opt/letsencrypt/letsencrypt-auto --debug
these steps always works for me.
I solved it following the next steps
Download certbot-auto by going to this link.
Delete letsencrypt folder:
sudo rm -rf /opt/eff.org/
Install cryptography module:
sudo python -m pip install cryptography
Run certbot-auto --debug
sudo ./certbot-auto --debug
It looks like I have multiple python installations, which are making things difficult -- e.g. pip will tell me that a package has been installed through pip freeze, but when attempting to use it within a program, I get an error that it does not exist. Here are a few diagnostic tests I've run:
>>> import sys
>>> sys.executable
'/usr/local/opt/python/bin/python2.7'
>>> sys.exec_prefix
'/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7'
>>> print '\n'.join(sys.path)
/usr/local/lib/python2.7/site-packages/setuptools-15.2-py2.7.egg
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
/Library/Python/2.7/site-packages/ipython-2.1.0-py2.7.egg
/Library/Python/2.7/site-packages/gnureadline-6.3.3-py2.7-macosx-10.9-intel.egg
/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg
/Library/Python/2.7/site-packages
As well as checking the path for python and some common tools:
which easy_install
/usr/local/bin/easy_install
which python
/usr/local/bin/python
which pip
/usr/local/bin/pip
How can I fix it, short of doing a clean re-install of OS X?
Edited to add $PATH and .bashrc info:
My $PATH is as follows:
Users/me/workspace/google-cloud-sdk/bin:/usr/local/bin:/Users/me/workspace/google-cloud-sdk/bin:/urs/local/bin:/Users/me/workspace/google-cloud-sdk/bin:/urs/local/bin:/Users/me/workspace/google-cloud-sdk/bin:usr/local/python:usr/bin/python:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/texbin: No such file or directory
-- the fact that it is returning an error makes me suspect that I've set up my .bash_profile wrong somehow. These are the only modifications I have made:
#Set architecture flags
export ARCHFLAGS="-arch x86_64"
#Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
#Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
# The next line updates PATH for the Google Cloud SDK.
source '/Users/me/workspace/google-cloud-sdk/path.bash.inc'
# The next line enables bash completion for gcloud.
source '/Users/me/workspace/google-cloud-sdk/completion.bash.inc'
And this is my .bashrc:
# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# cache pip-installed packages to avoid re-downloading
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
Couldn't find a way to fix it, so ended up doing a clean OS install and setting up a new python dev environment.
Please help me find the cause of this problem with my Django installation on Windows.
C:\Djangoprojects>django-admin.py startproject mydjangoblog
Traceback (most recent call last):
File "C:\Python27\Scripts\django-admin.py", line 4, in <module>
import pkg_resources
File "build\bdist.win-amd64\egg\pkg_resources.py", line 3007, in <module>
File "build\bdist.win-amd64\egg\pkg_resources.py", line 728, in require
File "build\bdist.win-amd64\egg\pkg_resources.py", line 626, in resolve
pkg_resources.DistributionNotFound: django==1.5.1
I just installed Django 1.5.1 and I remember I had the 1.4.3 before removing it. When I try to create a project, the above error is shown.
After a few adjustments - which included adding the whole directory of Python27\Lib\site-packages\django\bin to the path variable, this is the error I now get when I try to create a project:
C:\Djangoprojects>django-admin.py startproject djangoblog
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\django\bin\django-admin.py", line 2, in <module>
from django.core import management
ImportError: No module named django.core
The question am now asking myself is this: Where should I put the django folder? In its own place or within python27?
I can import Django through the Python Interactive shell without a problem.
I have also added django-admin.py to the system path variable just in case.
Thanks in advance.
I finally was able to fix this problem. Here is what I did after spending some time on Stackoverflow:
Leave everything the way it was installed by easy_install when I installed it.
Make sure that there is one django installation.
Make sure the django-admin.py is inside Python27\Scripts
To create a django project do: on the command line:
python C:\Python27\Scripts\django-admin.py startproject demosite instead of just: django-admin.py startproject demosite.
The easiest way to make creating projects easier, you can create a batch file called startproject.bat and save it inside Python27\Scripts\ folder. Inside that file, add the following: python C:\Python27\Scripts\django-admin.py startproject %1
Now, on your command line,you will be able to simply say : startproject.bat demosite
This worked out for me at last and I am happy to say this problem has been solved! I hope this was helpful to others as well.
I want to thank everyone who took their time to answer this question. I could have voted up your answer but I don't have enough points, but until then, I appreciate it.
There is an easy way is to install pip, the python package manager on Windows and install Django using pip. Pip will handle the environment variables and paths for you.
pip install django --upgrade
you can easily uninstall django by just deleting the folder C:\Python27\Lib\site-packages\django
new installation
download django https://www.djangoproject.com/download/1.5.1/tarball/
unzip Django-1.5.1.tar.gz
open terminal(start->run->cmd)
cd Django-1.5.1
python setup.py install
that is it.
now try django-admin.py startproject mydjangoblog
I suggest you to use virtualenv to maintain a clean python environment.
install virtualenv, and add it to your env-path
run cmd mkvirtualenv django to create the env for your django project
run pip.exe install to install needed libraries.
Above issue take place due multiple Django package installed on system. To overcome issue just remove all django package and reinstall latest django package on pc.
on linux
$ sudo pip uninstall Django == version
$ sudo pip install Django