I have just downloaded python 3.6.1 from github and built it in a local dir. Now I am trying to make a virtualenv with that version of python but I keep getting:
Running virtualenv with interpreter /home/giorgio/tools/cpython-3.6.1/python
Using base prefix '/usr/local'
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 2462, in <module>
main()
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 762, in main
symlink=options.symlink,
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 998, in create_environment
install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1219, in install_python
copy_required_modules(home_dir, symlink)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1147, in copy_required_modules
dst_filename = change_prefix(filename, dst_prefix)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1111, in change_prefix
assert False, "Filename {} does not start with any of these prefixes: {}".format(filename, prefixes)
AssertionError: Filename /home/giorgio/tools/cpython-3.6.1/Lib/os.py does not start with any of these prefixes: ['/usr/local', '/usr/local']
I don't want to install this version of python globally on the system. Is there another way to make virtualenv work with it?
I think Python 3.6 introduced a new way of creating virtual environments that don't depend on routing through usr/local.
python3 -m venv /path/to/new/virtual/environment
Here is documentation.
I ran into this error attempting to use my brew-installed version of Python 3.9.5 to create a new virtual environment on macOS. (mkvirtualenv with virtualenvwrapper)
My command format is typically:
mkvirtualenv -p python3 [env-name]
Not sure what caused this to get messed up, but ultimately I got it working again by running:
python3.9 -m venv ~/.virtualenvs/myenvname
This puts the env in your normal spot, and you can still run workon myenvname
The right way to achieve this is to set the prefix when you configure the build options to be a local directory and then perform make install. So if the directory you want to install things at is $HOME/pythons then in the build directory run:
./configure --prefix="${HOME}/pythons"
make
make install
Related
ive updated to python3 and downloaded virtualenv using:
sudo /usr/bin/easy_install virtualenv
when i go to start the virtualenv i got the following error message :
virtualenv project1
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
#_call_aside
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside
f(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 585, in _build_master
return cls._build_from_requirements(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'zipp>=0.4' distribution was not found and is required by importlib-resources
i looked around and realised the that 'zipp' had not been installed so i installed that also. when i went to run the virtualenv again i got the same error message again as above. and for some reason it keeps referencing python 2.7 even though ive upgraded to python3.
please try this ..
you just follow Exactly the bellow Items :
Open your Command Prompt AS ADMINISTRATOR -> right click on CMD and RUN AS ADMINISTRATOR
go to which Folder to you want to create your VirtualENV : For example : > Cd C:\Users...\Documents\python\src
type it : PIP install Virtualenv
make sure your internet connection is Ok
4.type : python -m venv env
and then you can create your project inside this env folder..
all Comment code should be write in Command Prompt AS Administrator
i ended up using the built in python 3 venv package. it works just as well and it was straight forward and simple. thank you for all the help
start the virtual environment: python3 -m venv project1
activate the virtual environment: source project1/bin/activate
deactivate the virtual environment: deactivate
If you're using Python 3.3 or later, you can use the built-in venv [https://docs.python.org/3/library/venv.html] module. This will reduce the number of dependencies, making installation and troubleshooting a bit easier.
To double-check that you are invoking the correct Python interpreter, run python3 -V or python -V (depending on how it's aliased).
Just try out.
virtualenv venv
It should create a venv directory in same directory if python 3.x is being used.
I generally use python2.7 for projects.
For one project, I need to use python 3.5+.
I installed python3 on Mac.
Also installed virtualenv using pip3.
Now when I run the command
virtualenv -p python3 test
I get the following error:
Running virtualenv with interpreter /usr/bin/python3
Already using interpreter /Library/Developer/CommandLineTools/usr/bin/python3
Using base prefix '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7'
New python executable in /Users/sourabh/virtualenvs/test/bin/python3
Also creating executable in /Users/sourabh/virtualenvs/test/bin/python
Traceback (most recent call last):
File "/Library/Python/3.7/site-packages/virtualenv.py", line 2632, in <module>
main()
File "/Library/Python/3.7/site-packages/virtualenv.py", line 870, in main
symlink=options.symlink,
File "/Library/Python/3.7/site-packages/virtualenv.py", line 1156, in create_environment
install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
File "/Library/Python/3.7/site-packages/virtualenv.py", line 1621, in install_python
shutil.copy(original_python, py_executable)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 245, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 103, in copyfile
if _samefile(src, dst):
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 88, in _samefile
return os.path.samefile(src, dst)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/genericpath.py", line 96, in samefile
s1 = os.stat(f1)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
For making a virtual environment with Python 3
Use this for making env
python3 -m venv env
To activate env
source env/bin/activate
Improve upon answer of #ParthS007 (Wanted to add a comment to the existing answer but couldn't due to not enough reputation):
Corrected the virtual environment name to be the common used one venv so it's easier for beginners like me to use/understand in conjunction with other tutorials.
Added how to deactivate and remove virtual environment too.
For making a virtual environment with Python 3
Use this for making env
python3 -m venv venv
To activate env
source env/bin/activate
To deactivate env
deactivate
To remove env
rm -rf venv
Trying to run virtualenv with my project, but it shows some errors. Couldn't find a right solution, unfortunately. Maybe someone has dealt with the same issue before.
(base) Organic:djangoproject organic$ mkvirtualenv py1
Using base prefix '/anaconda3'
New python executable in /Users/organic/.virtualenvs/py1/bin/python3
Traceback (most recent call last):
File "/anaconda3/bin/virtualenv", line 11, in <module>
load_entry_point('virtualenv==16.1.0.dev0', 'console_scripts', 'virtualenv')()
File "/anaconda3/lib/python3.6/site-packages/virtualenv.py", line 712, in main
symlink=options.symlink)
File "/anaconda3/lib/python3.6/site-packages/virtualenv.py", line 928, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/anaconda3/lib/python3.6/site-packages/virtualenv.py", line 1234, in install_python
shutil.copyfile(executable, py_executable)
File "/anaconda3/lib/python3.6/shutil.py", line 121, in copyfile
with open(dst, 'wb') as fdst:
OSError: [Errno 62] Too many levels of symbolic links: '/Users/organic/.virtualenvs/py1/bin/python3'
Thank you guys I have resolved this issue by figuring out how to switch onto a proper virtualenv throughout Anaconda on VS Code. So, for now, I'm using only (base) virtualenv that was already set up by default to conda. And all my last projects seem to be working with no side issues so far.
To whom that doesn't know on VS Code on MAC OS use shift+command+p -> Python: Select Interpreter, then select Anaconda interpreter Python 3.6.6 64-bit ('base': conda) anaconda3/bin/python. Notice that your virtualenv can have a different name instead 'base'.
After, again click shift+command+p choose Python: Create Terminal and VSC will run a terminal down below where your virtualenv will be turned on like in my situation (base) Organic:django_project organic$.
I was using the elastic beanstalk cli with AWS without any difficulty a few months ago. I wanted to update my website and ran into this error:
me$ eb status Traceback (most recent call last): File
"/Library/Frameworks/Python.framework/Versions/2.7/bin/eb", line 5, in
from pkg_resources import load_entry_point File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/init.py",
line 3095, in
#_call_aside File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/init.py",
line 3081, in _call_aside
f(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/init.py",
line 3108, in _initialize_master_working_set
working_set = WorkingSet._build_master() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/init.py",
line 660, in _build_master
return cls._build_from_requirements(requires) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/init.py",
line 673, in _build_from_requirements
dists = ws.resolve(reqs, Environment()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/init.py",
line 846, in resolve
raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'blessed==1.9.5' distribution
was not found and is required by awsebcli
I haven't been able to find anything about this error, except for a question about how to deal with a similar problem on ubuntu (I'm on a Mac) that has gone unanswered for a month.
Does anyone have any ideas?
This is most likely caused by the fact that the eb script is using Apple's Python interpreter instead of the one you installed yourself.
There are two workarounds:
1. Run the EB CLI in a virtual environment
Create a virtual environment for the EB CLI by running virtualenv ~/eb_cli_env.
Run source ~/eb_cli_env/bin/activate to activate the created virtual environment.
Run pip install awsebcli.
After that, you should be able to use the eb command just fine. You will have to run source ~/eb_cli_env/bin/activate every time before you can use the EB CLI.
--OR--
2. Edit the shebang line in the eb script
Run vim /usr/local/bin/eb.
Change the first line from #!/usr/bin/python to #!/usr/bin/env python.
This will ensure the eb command works globally without using a virtual environment, however it is very likely that if you upgrade the awsebcli package you will have to edit the shebang line again.
My suggestion is to install by brew on osx.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html#eb-cli3-install-osx
In my case I remove my previous installation by pip:
pip uninstall awsebcli
and run
brew install awsebcli
sudo pip install https://pypi.python.org/packages/2.7/b/blessed/blessed-1.9.5-py2.py3-none-any.whl
All I could find
Let me start by saying I'm new at programming, mac osx, and bash.
I'm having a tough time getting virtualenvwrapper setup on my Mac osx 10.7.3.
Its most certainly a path settings issue but I'm just having trouble getting it working.
Setup of virtualenvwrapper in .bashrc
export WORKON_HOME=$HOME/.Apps
source /usr/local/bin/virtualenvwrapper.sh
Some terminal output:
which easy_install
/usr/bin/easy_install
python -V
Python 2.7.1
When I run "source .bashrc" in the terminal I get no output.
When I run mkvirtualenv in the terminal I get:
Error [Errno 2] No such file or directory while executing command install_name_tool -change /System/Library/Fram.../Versions/2.7/Python #executable_path/../.Python 1/bin/python
Could not call install_name_tool -- you must have Apple's development tools installed
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.7.1.2', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.7/site-packages/virtualenv-1.7.1.2-py2.7.egg/virtualenv.py", line 928, in main
never_download=options.never_download)
File "/Library/Python/2.7/site-packages/virtualenv-1.7.1.2-py2.7.egg/virtualenv.py", line 1029, in create_environment
site_packages=site_packages, clear=clear))
File "/Library/Python/2.7/site-packages/virtualenv-1.7.1.2-py2.7.egg/virtualenv.py", line 1347, in install_python
py_executable])
File "/Library/Python/2.7/site-packages/virtualenv-1.7.1.2-py2.7.egg/virtualenv.py", line 966, in call_subprocess
cwd=cwd, env=env)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
OSError: [Errno 2] No such file or directory
You probably just need to install XCode. It should be a free (if large) download/install from the App Store.
For future reference, I highly recommend using a package manager and pip (instead of easy_install) for python development on OS X. My preferred package manager is Homebrew, but MacPorts and Fink are also good. Among other things, pip lets you uninstall stuff, which easy_install cannot simply do.