I have a number of django projects organized with the following directory structure using win7 (I'm using GIT_BASH/mingw for my command line) :
envs--r1--project1
--project2
--Include
--Library
--Scripts--python.exe
python275--
The idea being here that the different projects have a common environment and I can activate that environment from each projects root directory using:
$ source ../Scripts/activate
I don't understand exactly how it happened but it turned out that the interpreter ( listed above as python.exe ) was linked somehow to a second python folder above.
I deleted the python275 folder ( AAHH!!) , not realizing its importance, resulting in:
Traceback (most recent call last): File "C:\envs\r1\lib\site.py", line 703, in main() File "C:\envs\r1\lib\site.py", line 692, in main aliasmbcs() File "C:\envs\r1\lib\site.py", line 515, in aliasmbcs import locale, codecs File "C:\envs\r1\lib\locale.py", line 19, in import functools ImportError: No module named functools
I have reinstalled the correct python folder but the error persists. Can anyone advise me on how to rebuild the virtualenvs so I can go back to the way it was?
edit:
(r1)
/C/envs/r1/Scripts
$ import reload(functools)
sh: syntax error near unexpected token `('
(r1)
/C/envs/r1/Scripts
$ python.exe import reload(functools)
sh: syntax error near unexpected token `('
(r1)
/C/envs/r1/Scripts
$ python.exe reload functools
Traceback (most recent call last):
File "C:\envs\r1\lib\site.py", line 703, in <module>
main()
File "C:\envs\r1\lib\site.py", line 692, in main
aliasmbcs()
File "C:\envs\r1\lib\site.py", line 515, in aliasmbcs
import locale, codecs
File "C:\envs\r1\lib\locale.py", line 19, in <module>
import functools
ImportError: No module named functools
(r1)
/C/envs/r1/Scripts
$ reload(functools)
sh: syntax error near unexpected token `('
(r1)
/C/envs/r1/Scripts
$ python.exe reload(functools)
sh: syntax error near unexpected token `('
(r1)
/C/envs/r1/Scripts
$ python.exe test.py
Traceback (most recent call last):
File "f:\envs\r1\lib\site.py", line 703, in <module>
main()
File "f:\envs\r1\lib\site.py", line 692, in main
aliasmbcs()
File "f:\envs\r1\lib\site.py", line 515, in aliasmbcs
import locale, codecs
File "f:\envs\r1\lib\locale.py", line 19, in <module>
import functools
ImportError: No module named functools
I suggest reinstalling Python and virtualenv from scratch in your case, and then re-creating the environment(s).
Make sure you have a working Python 2.7.5 installation on your system.
Make sure you have pip installed (see docs).
Make sure pip is linked to the Python installation above (check the output of pip -V, it should contain the correct system-wide Python path).
Do a clean install of virtualenv using pip install virtualenv.
Create and activate the environment for your projects.
Reinstall within your new environment all the modules you had installed in your old environment.
This may be a tricky one.
If you have an up-to-date file such as requirements.txt
with all the packages required, then
you're all set (pip install -r requirements.txt should do it).
If you don't have requirements listed, or they aren't up-to-date, then
check manually which packages you had installed in your old environment.
For that you should locate site-packages directory within your old virtualenv
(should be under Library probably) and look what's in there.
Every non-system package you recognize in site-packages directory
you install into your new environment (normally using pip install but
some packages may have custom instructions).
That's what I did when it happened to me. I wasn't able to simply rebuild the environment, so I did the reinstall for cleanness.
Taken from other post. You can associate the virtualenv to a python version.
You indicate the Python interpreter to use with the flag -p or --python (e.g --python=python2.5)
virtualenv -p /usr/bin/python2.6 <path/to/new/virtualenv/>
But this is just works for creating new environments. You would need to access your old virtualenv and execute:
pip freeze > requirements.txt
The file requirements.txt would contain all the apps you installed in the old virtual environment and their respective versions. Now, from the new environment you have created, run:
pip install -r requirements.txt
You should active the virtual environment.
$ source /yourvirtualenvpath/bin/activate
$ pip freeze > /home/user/requirements.txt
$ deactivate
$ source /yourNEWvirtualenvpath/bin/activate
$ pip install -r /home/user/requirements.txt
Related
I have created a package named as patterns along with test.py,
test.py has the following code lines:
from patterns.shapes import *
square()
[Module Error]
I have copied the test.py file to the same location F:, where I trying to run via command prompt.
To gain access to this package from any location I have installed it using pip install . in the windows command prompt, which was successful, but when I try to access the file test.py I am getting the error as below :
F:\>py test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
from patterns.shapes import *
ModuleNotFoundError: No module named 'patterns'
My package folder is stored in a different drive.
While working on a python project, one must always work in a virtual environment. Please check if you have your virtual environment activated. If not, then follow the steps:
cd your_working_directory
virtualenv environment_name where environment_name can be any name you want.
environment_name/Scripts/activate if on Windows
Or environment_name/bin/activate if on MacOS
Then after activating the environment you can install all the dependencies using pip. i.e pip install patterns
When I create a new project in Google Cloud Console and just try to run
pip
I get this error:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/home/sguergachi/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 70, in <module>
import packaging.version
ImportError: No module named packaging.version
I'm not sure how to fix this. Reinstalling doesn't seem to be an option for google cloud as it would for local environment.
It seems to be able to do anything in pip on GCP you need to run as sudo.
sudo pip
This fixed my issue.
First, pip and python are for Python 2; pip3 and python3 are for Python 3. Prefer Python 3 as most apps are finally getting away from Python 2.
Install Python apps in your $HOME folder, which persists across your GCP time/space continuum:
pip3 install --user <app>
Note you'll want to add ~/.local/bin to your PATH environment variable, discussed at length in https://unix.stackexchange.com/a/26059/46798, by adding the following to ~/.profile:
# add local Python apps to PATH
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
I decided to give pelican a try, but when I run pelican-quickstart, I get the following dialog:
$ pelican-quickstart
Traceback (most recent call last):
File "/usr/local/bin/pelican-quickstart", line 9, in <module>
load_entry_point('pelican==3.4.0', 'console_scripts', 'pelican-quickstart')()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 357, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2394, in load_entry_point
return ep.load()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2108, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/Library/Python/2.7/site-packages/pelican-3.4.0-py2.7.egg/pelican/__init__.py", line 20, in <module>
from pelican.generators import (ArticlesGenerator, PagesGenerator,
File "/Library/Python/2.7/site-packages/pelican-3.4.0-py2.7.egg/pelican/generators.py", line 23, in <module>
from pelican.readers import Readers
File "/Library/Python/2.7/site-packages/pelican-3.4.0-py2.7.egg/pelican/readers.py", line 24, in <module>
from six.moves.html_parser import HTMLParser
ImportError: No module named html_parser `
There was a similar error message in this post, and since I'm running Python 2.7.6 on OS X 10.10 (Yosemite), there may be a similar issue.
What's the best way to address this?
Reinstall Pelican doesn't help me, so I made a little fix in pelican
Modifications were made in following file
/Library/Python/2.7/site-packages/pelican/readers.py
at line 24 place
from six.moves import html_parser
instead of
from six.moves.html_parser import HTMLParser
and at line 299
class _HTMLParser(html_parser.HTMLParser):
instead of
class _HTMLParser(HTMLParser):
Modification actual for pelican 3.6.0, but seems to applicable for other version if search for this lines in readers.py file. This is just quick workaround, hope this problem will be solved at pelican's side.
This error seems to come from Python 2.7.6 on OSX. When I install python via Homebrew and reinstall this module I got rid of this error.
$ pip uninstall pelican
$ brew install python
$ which python # should show /usr/local/bin/python
$ python -V # should show Python 2.7.8
$ pip install pelican
I think that you've probably encountered with version conflict problem in module six.
Try sudo pip install virtualenv to create an isolate python environment.
start
create your pelican path mkdir /path/to/pelican
go to /path/to/pelican and create an isolate python environment with virtualenv venv
activate virtualenv source venv/bin/activate
install pelican under the venv(without sudo!) pip install pelican markdown
done
and now you are free to any problem mentioned above. all the dependencies in the venv are isolated from the global environment.
To quit the venv, type deactivate
I was running into the same error message.
six was also already installed, but an old version (1.4.1)
pip install six --upgrade
Installed six 1.10.0, which made pelican-quickstart finally work :)
You may need to install six.
if you're using pip, try
pip install six
and then restart pelican-quickstart
Tonight I am trying to get the package called "requests" installed and have begun fumbling around with the terminal and do not have very much intuition when it comes to this sort of thing.
Computer is a mac mini, osx version 10.9.4
In /Library/Python I have 4 folders: 2.3 2.5 2.6 and 2.7.
In /Applications I have "Python 2.7" and "Python 3.4"
I can open IDLE and type 8+8 and I get 16 just fine.
Here is the error I am getting in terminal:
host-210-117:~ Mario$ python
ImportError: No module named site
host-210-117:~ Mario$ pip
ImportError: No module named site
My goal is to run this command in the terminal:
pip install requests
I believe pip is already installed. I run the file "get-pip.py" in IDLE and this is what it says:
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg
Cleaning up...
This may have something to do with paths? I would appreciate some guidance/hints/tips, thanks!
Oh and just a little more info that might help solve this question. Here is the first few lines of the program I'm running:
import base64
import hmac
import json
import requests
import time
import urllib
import os
Which gives me this error in IDLE (so I guess it importing those first few packages with no problem?) :
>>>
Traceback (most recent call last):
File "/Users/Mario/Desktop/pyak/pyak.py", line 4, in <module>
import requests
ImportError: No module named requests
>>>
***** System path list:
sys.path
['/Users/Mario/Desktop/pyak', '/Users/Mario/Documents', '/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']
*** another update:
host-210-117:~ Mario$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
*** a little more info (is this supposed to happen?)
host-210-117:~ Mario$ which pip
/usr/local/bin/pip
host-210-117:~ Mario$ pip
ImportError: No module named site
*** After changing .bashrc
.bashrc: here's what in the file
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
alias python=/Library/Python/2.7/python
here is the output of running:
pip install requests
host-210-117:~ Mario$ pip install requests
Downloading/unpacking requests
Downloading requests-2.4.1-py2.py3-none-any.whl (458kB): 458kB downloaded
Installing collected packages: requests
Cleaning up...
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 671, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 901, in move_wheel_files
pycompile=self.pycompile,
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 215, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 205, in clobber
os.makedirs(destdir)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/requests'
Storing debug log for failure in /Users/Mario/Library/Logs/pip.log
I met the same question, and error info is:
ModuleNotFoundError: No module named 'xxx'
and finally solved by
brew install python3
brew link python3
sudo python3 -m pip install xxx
// or `sudo python3 -m pip install -r requirements.txt`
From what I can tell you have three versions of Python on your system.
The one that comes with OSX /Library/Frameworks/Python.framework/Versions/2.7/
Python 2.7 from python.org /Library/Python/2.7/site-packages
Python 3.4 from python.org
pip is installed against the Python 2.7 version you downloaded (the one you see in your Applications folder), unfortunately the default Python for your shell is the one that's bundled with OSX, and there is no pip installed there.
IDLE is also bundled with the Python that you downloaded, which is why it keeps telling you that pip is installed, but it doesn't work from the shell.
Since you are probably using the Python downloaded from python.org as your "primary" Python (after all, its the one with IDLE that you are using), you need to set your shell environment to point to this Python as default.
The easiest way to do that is to add a variable in .bashrc that creates an alias python and points it to the right binary. To do that, add this line to /Users/yourusername/.bashrc - files with . are hidden by default, so you'll have to write the entire file name in the command line to open it. Add the following line:
alias python=/Library/Python/2.7/python
Save the file and then close all terminal windows and open it again. Now type pip and it should work correctly, and then you can proceed to installing requests.
For future reference, try to stick with one version of Python. I personally ignore the bundled version and use the one from brew, but you can stick to the Python downloaded from python.org.
I fixed mine with:
brew reinstall python
It fixed all my broken paths. I think I broke it with a broken brew package that had a wrong python version dependancy or something like that.
site.py is a standard module that is run by python by default. It allows tweaking sys.path and running some code before your code starts running. It should live in the standard library and can hardly be somehow absent. However, you can disable automatic importing of the module by passing -S switch to python.
Anyway, you should somehow inspect why the module can not be imported. Try to examine sys.path list.
You are trying to install the package in '/Library/Python/2.7/site-packages/requests' but it requires root permissions to do so. This should do the trick:
$ sudo pip install requests
I did some reading. The command line,
python3.10 -m pip install pandas
as long as you have the latest version of pip updated, this will install pandas to the specific python that you wanted otherwise it defaults to the latest version installed in my case Anaconda. You can change the python3.10 for your desired version of python to install too.
sudo easy_install pip
sudo pip install requests
I installed virtualenv using pip and now receive the following error whenever I actually try and use it:
% virtualenv
Traceback (most recent call last):
File "/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2705, in <module>
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 668, in require
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 571, in resolve
pkg_resources.DistributionNotFound: virtualenv==1.11.2
%
Similarly, I installed django with pip, and when I try and import django in python I get: ImportError: No module named django.
I tried to install virtualenv again, this time using easy_install instead of pip. easy_install gave me an error saying that it was having issues with my PYTHONPATH environment variable. Lo and behold, after reading http://www.stereoplex.com/blog/understanding-imports-and-pythonpath, PYTHONPATH is what python uses to find modules, and my PYTHONPATH was unset.
After setting PYTHONPATH to /lib/python3.3/site-packages (where pip was installing my modules), both virtualenv and importing django functioned properly.
Note: because I have both python2.7 and python 3.3 installed, for me pip actually installs packages to /lib/python2.7/site-packages while pip3 installs packages to the aforementioned /lib/python3.3/site-packages.
For the unfamiliar, information on setting environment variables can be found here: https://help.ubuntu.com/community/EnvironmentVariables