Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


4 questions online user: 14

0
votes
answers
110 views
+10

如何在使用virtualenv的django中運行芹菜時使用主管?

0

昨天,我部署nginx的,uwsgi,芹菜,監事一個Django項目。一切似乎都很好。如何在使用virtualenv的django中運行芹菜時使用主管?

但我有一些問題來了。

一般說,這個時候,我部署一個Django項目和使用的本地Python安裝,但如果我必須在虛擬環境中使用Python,我應該怎麼辦?

例如,我編寫了django網站用來控制某個計時任務的一些任務(django-celery),以及基於python3的django項目(python3環境在virtualenv中)。

所以,芹菜應python3,這在virtualenv中,而不是本地Python環境中使用。

這意味着,如果我在主管設置的命令爲:

command=python ****/manage.py celery 

然後將發生錯誤。

的uwsgi有對此,在那裏我可以設置的virtualenv的路徑一些設置。

但在上司,我無法看到某些設置或某種方式來使用的virtualenv。

請幫忙嗎?

沙发
0
0

在命令中包含的路徑到你的虛擬環境:

command=/path/to/venv/bin/python celery worker 
+0

非常感謝,我會嘗試這樣的。 – bigpang

0
votes
answers
119 views
+10

運行在PIP(康達)的virtualenv不激活第一

0

正如書名,我已經創造了一些ENV中暢達像這樣運行在PIP(康達)的virtualenv不激活第一

conda create -n myenv python=2.7 

我想一個命令來運行pip install的包膜內沒有做首先是source activate myenv。這可能嗎?我相信我使用任何方法將不得不制定出PATH等

+0

默認情況下,在'/ path/to/anaconda/envs/env-name'處創建環境,您可以在那裏查看。你爲什麼需要這樣做? – darthbith

沙发
0
0

假設你在Bash shell環境中使用蟒蛇,其中一個方案是爲您創建的虛擬環境中添加水蟒bin路徑到您的PATH變量這樣一個命令,即虛擬環境中的pip二進制位於系統pip之前。

如果蟒蛇虛擬環境位於默認.conda目錄在你的home目錄,你可以做到這一點,如下所示:

export PATH=~/.conda/envs/myenv/bin:$PATH 

如果你想這是你的shell環境的默認行爲,您可以添加上面的命令給你的~/.bashrc文件。

此方法類似於爲設置PATH變量而建議的方法,以使您能夠在「根」環境detailed in the Anaconda documentation中使用Anaconda二進制文件。

0
votes
answers
89 views
+10

「OSError:mysql_config找不到」當試圖「點安裝mysqlclient」 - Django

-1

我是相對較新的Django和一般的Web開發。「OSError:mysql_config找不到」當試圖「點安裝mysqlclient」 - Django

我想

pip install mysqlclient 

在我

virtualenv -p python3 

到Django的2.0掛鉤到MySQL。不過,我得到這個錯誤:

Collecting mysqlclient 
Using cached mysqlclient-1.3.12.tar.gz 
Complete output from command python setup.py egg_info: 
/bin/sh: mysql_config: command not found 
Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
    File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup.py", line 17, in <module> 
    metadata, options = get_config() 
    File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup_posix.py", line 44, in get_config 
    libs = mysql_config("libs_r") 
    File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup_posix.py", line 26, in mysql_config 
    raise EnvironmentError("%s not found" % (mysql_config.path,)) 
OSError: mysql_config not found 

---------------------------------------- 
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/ 

我已經環顧四周,尋找答案了幾個小時,是的,我已經簽出thisthis,但似乎沒有奏效。

任何幫助將不勝感激!

+0

您已經鏈接到其他的問題,但你還沒說你是哪個操作系統上,或發生了什麼當你運行建議的命令。 – Alasdair

+0

@Alasdair我正在運行MacOS High Sierra(版本10.13.1)。當我運行:'sudo apt-get install python-dev python3-dev'我得到:'sudo:apt-get:command not found'例如 –

+0

'apt-get'是一些軟件包管理器和Debian。在MacOS上運行這些命令沒有任何意義。 – Alasdair

沙发
0
1

您應該克隆的mysql回購開始:

git clone https://github.com/PyMySQL/mysqlclient-python 

那麼你將獲得mysql-connector-c。您可以通過執行獲得它:

brew install mysql-connector-c 

在文本編輯器,然後打開/usr/local/bin/mysql_config

從Github上issue

有在mysql_config線,如下列:

# Create options 
libs="-L$pkglibdir" 
libs="$libs -l " 

它應該是:

#Create options 
libs="-L$pkglibdir" 
libs="$libs -lmysqlclient -lssl -lcrypto" 

保存該文件,並在那裏換回來的目錄,你下載回購。現在打開site.cfg文件。 取消註釋(刪除#)

#mysql_config = /usr/local/bin/mysql_config 

保存的是並運行:

python3 setup.py install 
+0

感謝您的支持。當我運行:'brew install mysql-connector-c'時,出現錯誤:'-bash:brew:command not found' –

+0

install [brew](https:// brew。sh) –

+0

您好Pranjal,好,我已經下載了Homebrew,成功運行'brew install mysql-connector-c',在我的文本編輯器中成功打開'/ usr/local/bin/mysql_config',但現在我不確定編輯文件到:libs =「 - L $ pkglibdir」 libs =「$ libs -lmysqlclient -lssl -lcrypto」任何幫助將不勝感激 –

188
votes
answers
85 views
+10

你如何在已經創建的virtualenv中設置你的pythonpath?

我編輯什麼文件,以及如何編輯?我創建了一個虛擬環境。

up vote 111 down vote accepted favorite
沙发
+1110
+50

EDIT #2

The right answer is @arogachev's one.


If you want to change the PYTHONPATH used in a virtualenv, you can add the following line to your virtualenv's bin/activate file:

export PYTHONPATH="/the/path/you/want"

This way, the new PYTHONPATH will be set each time you use this virtualenv.

EDIT: (to answer @RamRachum's comment)

To have it restored to its original value on deactivate, you could add

export OLD_PYTHONPATH="$PYTHONPATH"

before the previously mentioned line, and add the following line to your bin/postdeactivate script.

export PYTHONPATH="$OLD_PYTHONPATH"
+650

The comment by @s29 should be an answer:

One way to add a directory to the virtual environment is to install virtualenvwrapper (which is useful for many things) and then do

mkvirtualenv myenv
workon myenv
add2virtualenv . #for current directory
add2virtualenv ~/my/path

If you want to remove these path edit the file myenvhomedir/lib/python2.7/site-packages/_virtualenv_path_extensions.pth

Documentation on virtualenvwrapper can be found at http://virtualenvwrapper.readthedocs.org/en/latest/

Specific documentation on this feature can be found at http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html?highlight=add2virtualenv

+100

You can create a .pth file that contains the directory to search for, and place it in the site-packages directory. E.g.:

cd $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
echo /some/library/path > some-library.pth

The effect is the same as adding /some/library/path to sys.path, and remain local to the virtualenv setup.

我不想輸入絕對路徑,因為我的工作區在我的文件系統中移動。而且,我的項目路徑有空格。所以,我輸入了稍微修改過的命令:pushd“$(venv / bin / python -c”來自distutils.sysconfig import get_python_lib; print(get_python_lib())“)”... path / to / project / venv / lib / python3.7 / site-packages ... path / to / project echo ../../../../src> my_project.pth popd然後我停用了我的virtualenv,並重新激活了。我現在可以運行需要知道項目目錄所在位置的項目代碼。 - Jim DeLaHunt 2月11日凌晨4點01分

這是正確的答案。修改供應商提供的腳本(/ bin / activate)是一種弊端,安裝第三方工具不如使用內置方法來實現同樣的目的。 - 紅3月6日8:30

+10

I modified my activate script to source the file .virtualenvrc, if it exists in the current directory, and to save/restore PYTHONPATH on activate/deactivate.

You can find the patched activate script here.. It's a drop-in replacement for the activate script created by virtualenv 1.11.6.

Then I added something like this to my .virtualenvrc:

export PYTHONPATH="${PYTHONPATH:+$PYTHONPATH:}/some/library/path"
+10

After initializing your vertualenv(1. cd venv and 2. source bin/activate).

just set or change your python path by entering command following-

export PYTHONPATH='/home/django/srmvenv/lib/python3.4'

for checking python path enter 1)

type  python then 
>> import sys
>> sys.path

Thanks you...

-190

It's already answered here -> Is my virtual environment (python) causing my PYTHONPATH to break?

UNIX/LINUX

Add "export PYTHONPATH=/usr/local/lib/python2.0" this to ~/.bashrc file and source it by typing "source ~/.bashrc" OR ". ~/.bashrc".

WINDOWS XP

1) Go to the Control panel 2) Double click System 3) Go to the Advanced tab 4) Click on Environment Variables

In the System Variables window, check if you have a variable named PYTHONPATH. If you have one already, check that it points to the right directories. If you don't have one already, click the New button and create it.

PYTHON CODE

Alternatively, you can also do below your code:-

import sys
sys.path.append("/home/me/mypy") 

-1:這解決了用戶的PYTHONPATH,而不是virtualenv的PYTHONPATH。 - twneale 12年1月30日在19:07