Saya menjalankan Precise Pangolin amd64. Saya menginstal Python 3.3 dari ppa: fkrull / deadsnakes.
Sekarang saya ingin benar-benar menggunakan versi Python baru ini dalam virtualenv. Tetapi bagaimana saya bisa melakukan ini? Saya mendapatkan kesalahan berikut:
$ virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
Running virtualenv with interpreter /usr/bin/python3.3
The --no-site-packages flag is deprecated; it is now the default behavior.
New python executable in /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3
Also creating executable in /home2/USERNAME/.virtualenvs/pywork3/bin/python
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/site.py", line 73, in <module>
__boot()
File "/usr/local/lib/python2.7/site-packages/site.py", line 2, in __boot
import sys, imp, os, os.path
ImportError: No module named 'imp'
ERROR: The executable /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3 is not functioning
ERROR: It thinks sys.prefix is '/home2/USERNAME/.virtualenvs' (should be '/home2/USERNAME/.virtualenvs/pywork3')
ERROR: virtualenv is not compatible with this system or executable
Jika sebaliknya, saya secara eksplisit menggunakan python3.3
untuk memanggil virtualenv, saya mendapatkan kesalahan ini:
$ python3.3 /usr/bin/virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 2, in <module>
import virtualenv
ImportError: No module named 'virtualenv'
Aku terjebak. Setiap bantuan sangat dihargai!
EDIT: Mengikuti saran dari @thefourtheye, saya membersihkan site-packages
direktori lokal saya (secara efektif hanya menghapus site.py
). Sekarang saya melangkah lebih jauh, tetapi virtualenv mengeluh tentang yang hilang easy_install
:
Error [Errno 2] No such file or directory:
'/home2/USERNAME/.virtualenvs/pywork3/bin/easy_install' while executing command
/home2/USERNAME/.virt...rk3/bin/easy_install /usr/share/python-virtualenv/pip-1.1.tar.gz
Saya memang menginstal paket python3-setuptools
, yang menginstal versi easy_install versi Py3.
EDIT2:
Berikut ini adalah keluaran verbose, tanpa secara eksplisit lewat --distribute
dan --no-site-packages
, karena kedua sakelar ini adalah perilaku default dari virtualenv saya :
$ virtualenv --verbose -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
Running virtualenv with interpreter /usr/bin/python3.3
Creating /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3
Symlinking Python bootstrap modules
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/config-3.3m
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/lib-dynload
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/os.py
Ignoring built-in bootstrap module: posix
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/posixpath.py
Cannot import bootstrap module: nt
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/ntpath.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/genericpath.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/fnmatch.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/locale.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/encodings
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/codecs.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/stat.py
Cannot import bootstrap module: UserDict
Cannot import bootstrap module: copy_reg
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/types.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/re.py
Cannot import bootstrap module: sre
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/sre_parse.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/sre_constants.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/sre_compile.py
Ignoring built-in bootstrap module: zlib
Cannot import bootstrap module: _abcoll
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/warnings.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/linecache.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/abc.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/io.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/_weakrefset.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/copyreg.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/tempfile.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/random.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/__future__.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/collections
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/keyword.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/tarfile.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/shutil.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/struct.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/copy.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/base64.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/bisect.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/_dummy_thread.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/hashlib.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/heapq.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/hmac.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/reprlib.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/rlcompleter.py
Symlinking /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/weakref.py
Creating /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/site-packages
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/site.py
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/orig-prefix.txt
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/no-global-site-packages.txt
Creating parent directories for /home2/USERNAME/.virtualenvs/pywork3/include
Symlinking /home2/USERNAME/.virtualenvs/pywork3/include/python3.3m
Creating /home2/USERNAME/.virtualenvs/pywork3/bin
New python executable in /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3
Changed mode of /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3 to 0o755
Also creating executable in /home2/USERNAME/.virtualenvs/pywork3/bin/python
Changed mode of /home2/USERNAME/.virtualenvs/pywork3/bin/python to 0o755
Testing executable with /home2/USERNAME/.virtualenvs/pywork3/bin/python3.3 -c "
import sys
prefix = sys.prefix
if sys.version_info[0] == 3:
prefix = prefix.encode('utf8')
if hasattr(sys.stdout, 'detach'):
sys.stdout = sys.stdout.detach()
elif hasattr(sys.stdout, 'buffer'):
sys.stdout = sys.stdout.buffer
sys.stdout.write(prefix)
"
Got sys.prefix result: '/home2/USERNAME/.virtualenvs/pywork3'
Creating /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/distutils
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/distutils/__init__.py
Writing /home2/USERNAME/.virtualenvs/pywork3/lib/python3.3/distutils/distutils.cfg
Using existing distribute egg: /usr/share/python-virtualenv/distribute-0.6.24.tar.gz
Installing distribute..............................................................................................................................................................................................................................................................................................................................................................................................................done.
Installing existing pip-1.1.tar.gz distribution: /usr/share/python-virtualenv/pip-1.1.tar.gz
Installing pip...
Error [Errno 2] No such file or directory: '/home2/USERNAME/.virtualenvs/pywork3/bin/easy_install' while executing command /home2/USERNAME/.virt...rk3/bin/easy_install /usr/share/python-virtualenv/pip-1.1.tar.gz
...Installing pip...done.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 2283, in <module>
main()
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 938, in main
never_download=options.never_download)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1054, in create_environment
install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 643, in install_pip
filter_stdout=_filter_setup)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 976, in call_subprocess
cwd=cwd, env=env)
File "/usr/lib/python3.3/subprocess.py", line 818, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.3/subprocess.py", line 1416, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/home2/USERNAME/.virtualenvs/pywork3/bin/easy_install'
distribute
):virtualenv --no-site-packages -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
?--setuptools
juga, dan hasilnya persis sama (termasuk instalasi distribusi).Jawaban:
Ambil cadangan paket situs.
cp -r /usr/local/lib/python2.7/site-packages/ /tmp/site-packages
Pangkas direktori itu
rm -rf /usr/local/lib/python2.7/site-packages/
Sekarang coba yang sama
virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
Untuk menginstal tanpa pip
virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3 --no-pip
EDIT: Sepertinya versi virtualenv (1.7.1.2) dan python3.3 tidak kompatibel. Jadi, silakan coba ini
Copot python-virtualenv menggunakan
sudo apt-get remove python-virtualenv
wget http://peak.telecommunity.com/dist/ez_setup.py; sudo python ez_setup.py
Ini akan menginstal easy_install terbaru.sudo easy_install pip
sudo pip install virtualenv
virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
sumber
virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3 --verbose
dpkg -i
. Tampaknya bekerja sekarang. Terima kasih banyak!Python 3.3 memiliki venv built-in.
http://docs.python.org/3/library/venv.html#module-venv
Cukup jalankan
Dan untuk mengaktifkannya
Versi built-in dari virtualenv ini jauh lebih fleksibel daripada apa yang mungkin Anda terbiasa. Misalnya, Anda dapat memperluas EnvBuilder untuk melakukan hampir semua yang Anda inginkan. Anda dapat menyalin contoh implementasi EnvBuilder dari tautan di bawah ini dan bermain dengannya: http://docs.python.org/3/library/venv.html#an-example-of-extending-envbuilder
Script di atas kemungkinan melakukan sebagian besar dari apa yang kita harapkan untuk keluar dari virtualenv. Jadi, jika Anda hanya memerlukan virtualenv dengan easy_install dan pip, Anda harus siap.
Lihat suntingan @MarkOfSine di bawah ini untuk klarifikasi tentang cara menjalankan jika Anda masih bingung.
Untuk menambahkan di atas, dan sesuai dokumen:
Misalnya, setelah mengeksekusi:
pyvenv-3.3 /path/to/my_project/venv
Anda dapat menjalankan
distribute_setup.py
, yang tampaknya melakukan berbagai hal, tetapi pada dasarnya Anda berakhir denganeasy_install
di./my_project/venv/bin
direktori Anda .Ini kemudian dapat digunakan untuk menginstal
pip
dan sejenisnya.Itu tidak mengatakan dari mana Anda harus mendapatkan
distribute_setup.py
, jadi saya mengunduh dari:dan menggunakan lingkungan yang diaktifkan:
berlari:
dan
Yang kemudian menyelesaikan pengaturan lingkungan virtual lebih sejalan dengan virtualenv pada python 2.x
sumber
./venv/bin/easy_install pip
.Lebih mudah daripada yang terlihat:
benar-benar bekerja :)
sumber
Anda melakukan ini terlalu rumit. Jika dimasukkan
python3
, buat saja dengan:Anda bahkan dapat membuat alias jika mau
Tergantung pada mesinnya, Anda mungkin perlu menentukan juru bahasa:
sumber
python3-venv
ini juga diperlukan, setidaknya di Ubuntu 14.04.python3.4-venv
.Langkah-langkah yang berhasil bagi saya: Di MAC OSX 10.9.5
Unduh dan pasang Python-3.4.3 secara manual .
Buat virtualenv.
Catatan:
virtualenv -p <path to python3> py3env
tidak berfungsi:sumber
libssl-dev
danzlib1g-dev
agar python dikompilasi dengan _ssl.so zlib.sosumber