Pythonプロジェクトの仮想環境を構築できませんでした


問題


Replit Was Unable to Build the Virtual Environment for Python Project or the Project Not Giving Results As We Expected.

This Issue Can also happened to Other Online IDEs Also Like Glitch.


詳細


Most Online IDE Already Use Virtual Environment By default already. even if you create an virtual environment with python -m venv venv it will not gonna run again in next run like next day and all packages install with pip install -- needs to install again.

The venv by python -m venv venv for replit is not efficient.


ファーストソリューション


Replit uses Poetry Virtual Environment By Default for Python Project. Those are given below.

Note These should run under the shell tab not the console tab.


PIPコマンド
詩で命令するpython main.pypoetry run python main.pypip install package_namepoetry add package_namepython -m venv venvpoetry initsource venv/bin/activatepoetry shellpython manage.py runserverpoetry run python manage.py runserver

Mostly just add poetry run at first of running script like add this script to runner file of replit.

Click 3 dots in Open Editor of replit and click Show Hidden File and Edit the File Named .replit to given below.


language = "python3"
run = "poetry run python manage.py runserver 0.0.0.0:800"
# this is for django

二次解


Try Installing the alternative virtual environment named pipenv for the installing packages via requirements.txt file.

For Local Environment we add this package like pip install pipenv but for replit online IDE we go into shell tab and then add package by poetry.


poetry add pipenv

# then run below comman to install dependencies from requirements.txt file
pipenv -r requirements.txt

For pipenv Most Commands are already similar you just need to replace the word pip with pipenv.
For Activating Pipenv Virtual Environment type pipenv shell

.replit should have something like below run command.


language = "python3"
run = "pipenv install && pipenv run manage.py runserver 0.0.0.0:8000"
# just like given below but upper will work perfectly.
# run = "pipenv run manage.py runserver 0.0.0.0:8000"

This Commands for mostly running outside virtual environment without activating it directly.


PIPコマンド
Pipenvコマンドpython main.pypipenv run python main.pypip install package_namepipenv install package_namepython -m venv venvpipenv initsource venv/bin/activate && pip install -r requirements.txtpipenv shell && pipenv shellまたはちょうどpipenv installpython manage.py runserverpipenv run python manage.py runserver

結論


I Will Suggest You Use Poetry Because It Have Some Features for replit.

  • 高速インストールとファイルのruntingプロセス(Pipenvに比べて).
  • パッケージは、次の日に再びreplを開けた後に、削除されません.
  • CPU負荷はpipenvに比べて低かった.
  • 私は依存関係をインストールするためにパッケージを実行し、パッケージはGithubでhome-assistant/coreをデバッグするために50以上の依存関係を持っていました.
  • CPUは過熱していたが、CPU USAGS (私のため)のラインを越えなかった.
  • ReplitはオンラインのIDEで、クラウドをホスティングし、共同プログラミング環境を作ります.私はしばらくの間、ユーザーでした、そして、私は本当に私が彼らについて好きであるものを声に出したいです.
    いずれかのソリューションが何らかの方法であなたを助けた場合の反応を与える.
    バイ👋.